9

I've searched a round quite a bit in the past and present for either a builtin feature or program for this, but had no luck. I want to password protect a folder, but do not wish to encrypt it.

The security of the contents of the folder is not important, the password would just act as a deterrent to somebody attempting to access the contents of the folder from my computer. Think of it like a password lock on a computer, if you were to remove the harddrive you could easily take all the files the user had, but the password is still a deterrent so that not everyone passing by can just hop on.

Two main reasons to not use encryption here are:

  • Decreased performance for opening files
  • Encryption prevents the contents from being indexed/searchable

Is anybody aware of a solution?

3
  • 2
    Your first argument is not valid. On modern systems there is no performance penalty for encryption.
    – dotancohen
    Nov 24, 2014 at 6:19
  • 6
    @dotancohen: Sure there is. It's just an insignificant performance penalty.
    – Reid
    Nov 24, 2014 at 14:45
  • Password protect without encryption: Also known as Authentication
    – Porcupine
    Jan 31, 2020 at 13:17

2 Answers 2

16

The easiest way would be to change the permissions of the files to not be readable by anyone other than the owner. Once that is done, a user would have to either log in as you (which should require a password) or sudo as root (which also should require a password). To change the permissions, simply use the following command on any files you don't want others to have access to.

chmod og-rwx filename

This assumes that when you are not on the machine, your screen is locked and there is a password for your account as well as the root account.

1
  • 2
    This is the Unix way of handling the situation!
    – dotancohen
    Nov 24, 2014 at 6:18
9

Create a new user (with password) for this protected files/directories.

Then log in / sudo to root and give this commands (replace $newuser with the new user account name ;):

chown $newuser filename directoryname
chmod og-rwx filename directoryname

This way, the files and directories are even save when you don't log out and have your screen not locked for some reason.

This assumes, that a) you are not constantly logged in as root or any other account with special administrative rights, b) root (and any other user account with administrative rights) has a password set, c) sudo is not configured to skip password test (or in more general: entering the password is required for all log-in operations). d) every one with administrative access logs out when she leaves the terminal - even if only for a short time like 2 minutes.

/edit to reflect R Schultz'es comment

2
  • If you have the ability to create a new user, you have admin rights. If you have admin rights and you don't log out/lock your screen the files are still not safe no matter were you put them. This is because the person that sits down and uses your account will have the same admin rights and be able to access them in a variety of ways. If you don't have admin rights, the chmod is not guaranteed to work since you are no longer the owner of the file and in all likelyhood, the group and other permissions are not set to allow writing.
    – R Schultz
    Sep 24, 2015 at 2:43
  • I assume, that almost everyone logs in as unprivileged user nowadays. So a »sudo« plus passwort is required for this to work. Sep 25, 2015 at 10:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .