creating-ssh-user-provide-permission-only-a-specific-folder

Creating ssh user and provide permission only to a specific folder

Creating ssh user and provide permission only to a specific folder

Creating ssh user and provide permission only to a specific folder
This process is simple and easy.

First You need to login to your vps or dedicated server.

Once logged in, create a user by the below command and set password for the created user.
eg. earneasy is the username we are creating here.

root@server # adduser --home /home/directory-name earneasy

Now, we will change the folder permission so the user can create, delete or modify the files in the directory.

root@server # chmod 755 -f /home/directory-name/

Now change the ownership of the folders, so this user can access the folder.

root@server # chown earneasy:earneasy /home/directory-name/

You can also set the directory to open, when you connect through a shell access.
This can be accomplished by editing the shell configuration file.
Which can be found at /etc/ssh/sshd_config

Use nano text editor and open the file.

and add the below lines.
Match user earneasy
ChrootDirectory /home/directory-name/public
Subsystem sftp internal-sftp

root@server # nano /etc/ssh/sshd_config

Match user earneasy
ChrootDirectory /home/directory-name/public
Subsystem       sftp    internal-sftp

Press CTRL + O and CTRL + X to save and exit the file.

Once you saved the file, You should restart the ssh service to take effect.

root@server # service sshd restart

IMPORTANT :
While you doing this make sure, You have another session live, incase you did something wrong you can always revert back and work again.
make sure you take backups of the config file.
eg.

 
root@server # cp /etc/ssh/sshd_config /etc/ssh/sshd_config-bak

Do give us your feedbacks and queries on the comments section, I will be happy to address.

Comments

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