Restrict folder access in Ubuntu

19,145

Solution 1

As the owner or root, execute the command

# chmod -R 700 /path/to/folder

The chmod command changes the permissions of the file/folder. The 700 means that the owner has full access, and no one else. The -R means to apply the rules recursively (through subfolders). You will also want to run a chown

# chown user:user -R /path/to/folder

The chown command changes the owner of the file/folder. The user: part is the username to apply the owner as; the :user part is for the group. Every user typically has it's own group as well. Again, the -R is to recurse through to subfolders.

Solution 2

To add to Canadian Luke's answer:

It is actually not required to set the entire contents (recursively) of a folder to chmod -R 700.

In order to access a directory or any child content, you need +x permissions for your user. If you remove that the user can not access any of the child contents of this folder, no matter what the permission of the contents are.

In the above case, the command below would be enough:

# chown user:group /path/to/folder
# chmod go-x /path/to/folder

That way you can restrict access without changing the permissions or ownership inside your folder.

Solution 3

I'd suggest taking a look at encfs. It's easy to set up and use, and will encrypt a directory using the password of your choice. On ubuntu, it's available via apt as the encfs package. Setting up a new encfs volume is as easy as

$ encfs ~/.priv ~/priv

where ~/.priv will be the encrypred version. See the link in this post for a more detailed intro to the tool.

Share:
19,145

Related videos on Youtube

Andres
Author by

Andres

Software Engineer who loves programming, interested on Machine Learning. https://www.linkedin.com/in/andresarrieche/

Updated on September 18, 2022

Comments

  • Andres
    Andres over 1 year

    I want nobody to access my private folder, I'd like to set a password for it or just make it only accessible by root user.

    How can I get it? I'm using Ubuntu.