Skip to content
Blog SSH/SFTP: Create and Restrict a User to his Home Directory on a Ubuntu Server

SSH/SFTP: Create and Restrict a User to his Home Directory on a Ubuntu Server

This is a step by step guide to create a new user and restrict the user to his home directory.

1. Create a new user


sudo adduser TestUser

2. Change the ownership of TestUser’s home directory to root.


sudo chown root:root /home/TestUser

3. Edit the ssh config file


sudo vim /etc/ssh/sshd_config

and add the following lines to it:


Match user TestUser
ChrootDirectory /home/TestUser
AllowTcpForwarding no
ForceCommand internal-sftp

4. Restart SSH Service


sudo service ssh restart

Now, try logging in as the TestUser.

Hope it helps!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.