There are a few ways to password protect a folder on Linux/Unix without encryption. One way is to use the sudo command to run the command “passwd” in the folder where you want to password protect. Another way is to use the mkdir -p command to create a new folder and then use the sudo command to create a new user account for that folder and password protect that user account.


If you do not need or want to encrypt files on your computer but would like to stop casual snooping, then what is the best method for password protecting your folders on Linux/Unix? Today’s SuperUser Q&A post has helpful answers to a curious reader’s question.

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

Photo courtesy of Nathan Meijer (Flickr).

The Question

SuperUser reader Zane Woodard wants to know how to password protect a folder on Linux/Unix without encryption:

Is there an easy solution that Zane could use to password protect his folder?

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 hard-drive, you could easily take all the files the user had, but the password is still a deterrent to people accessing the contents of the drive.

Two main reasons for not using encryption here are:

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

Is anybody aware of a solution?

The Answer

SuperUser contributors R Schultz and Bodo Thiesen have the answer for us. First up, R Schultz:

Followed by the answer from Bodo Thiesen:

chmod og-rwx filename

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

Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

chown $newuser filename directoryname chmod og-rwx filename directoryname

This way, the files and directories are safe even if you do not log out and have your screen unlocked for some reason.