Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm running Ubuntu Server 12.04. I was wondering how I can set up a user to only access one directory. For example, I want to create a user 'brad' and want him to only have access to /var/www/brad. There, he can add and edit files as he pleases. Also, how could I give him access to phpmyadmin to create db's?

share|improve this question
How does brad connect to the machine? Will he have physical access? SSH? FTP? –  terdon Apr 27 at 21:08
Why would you want to do this? If he literally only has access to one directory he won't be able to do much. –  Warren Hill Apr 30 at 9:40
add comment

1 Answer 1

sudo adduser brad
sudo chown brad:brad /var/www/brad

man adduser and man chown for more information and advanced options. Notice the chown above will only give ownership of the directory, use -R flag to do it recursively. Also notice no other user except brad will have ownership of said directory. You might need to change permissions for other users with chmod. Read about file permissions here.

You can also do:

sudo chown me:brad /var/www/brad

So you are the owner and brad is the group which has access to it (brad is the only member of said group). Or the other way around:

sudo chown brad:my_group /var/www/brad

Notice www-data might need access to said folder (and sub-directories and files) for the webserver to function properly.

Also how could I give him access to phpmyadmin to create db's?

You should configure that in your webserver / through phpmyadmin. If permission is denied for some reason, just adjust it with chown or chmod.

share|improve this answer
-1: This will simply give brad access to /var/www/brad it will not stop him from having access to other directories. For example, his $HOME will still be /home/brad and he will be able to happily access all system directories. –  terdon Apr 27 at 21:09
@terdon umask is 0022 on Debian-based systems. It doesn't matter how he creates the user, it'll always be able to read most folders, since that's the default behavior (755 for folders and 644 for files). However, created as mentioned, brad only belongs to the brad group and only has write permissions to the brad folder (and some others, such as /tmp, which also doesn't matter how he'd create the user, since it's 777 by default). If he doesn't want a dir at /home he just has to append --no-create-home to adduser, as specified in the man page I mentioned for advanced options. –  Alex Apr 28 at 0:13
Note that the OP mentioned "add and edit files". I took that as write permissions. If he doesn't want read permissions I guess he'd have to chmod most of the system and possibly break something or set umask to something else and re-install everything from scratch (and possibly break something in the process). –  Alex Apr 28 at 0:17
I know, that's why I posted a comment and not an answer :). It is actually possible and might be easy depending on how the user connects. We need more details from the OP but sandboxing a user account is possible. However, the approach you describe does not stop brad from having write access both to /tmp and to /home/brad which will be created automatically by adduser, it simply gives brad write access to /var/www/brad and does not restrict the user in any way. –  terdon Apr 28 at 0:29
This is overkill Setup a vhost... dont point Brad to var/www point the vhost to /home/brad/public_html/<whatever>, then chown of /var/www to apache, point your hosts file to your vhost –  E Carter Young Apr 28 at 22:20
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.