Report this

What is the reason for this report?

How do I restrict a user to a specific directory?

Posted on November 30, 2015

I am relatively new to unix server admin, so this question may seem dumb. I am running a CentOS 7 droplet. I have created a new user and set the users home directory to /var/www/blablabla/public_html via usermod. I guess I really have two questions:

  1. How do I restrict the user to only be able to do anything within that folder? (ie: that folder is the user’s root and they cannot view/edit anything higher in the directory tree)

  2. Can I restrict a user from connecting via SSH while still allowing them to connect via SCP? And if so, how?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

If you do not want to use user home directory eg. /home/exampleuser then ssh cofiguration should be like this Subsystem sftp internal-sftp Match group sftpusers

ChrootDirectory %h

ForceCommand internal-sftp

Restart ssh service then it will work for you.

Hello guys,

In the article shows that when typing the command ls -al would show something like this:

root:root /home/ root:root /home/exampleuser/ root:root /home/exampleuser/htdocs/

exampleuser:sftpusers /home/exampleuser/htdocs/public_html

But typing the command shows me this result: https://screenshot.net/pt/1yxyxhx

using the cd command and then the ls -al command: https://screenshot.net/pt/rlnlnf6

As for permission, I used the command:

chown -R exampleuser examplegroup /var/www/my-site.com/wp-content

but the /wp-content folder is already existing and already has the permission www-data:www-data. So I can change it to exampleuser:sftpusers, no problem?

Anyway, I am not able to access SFTP with this new user when placed in the group, ie I have an existing user and he accesses normally, but accesses all folders of the server. Then I create the group, put the user in the group with the command below, and do the rest of the steps shown in the article, but after that the user no longer enters:

usermod -g newgroup -d /var/www/my-site.com/wp-content -s /sbin/nologin existinguser

Can someone help me?

Thanks.

how can i restrict user to his home directory only, who is logging through key in filezilla? Please let me know the way

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.