How to create a SFTP user


1) Log into SFTP server.

2) Create the SFTP user with no shell.
useradd -s /sbin/nologin -d /home/UserName -m UserName

3) Craete the directory to upload files.
mkdir -p /home/UserName/ftpsite/upload

4) Change the permission of user’s home directory.
chown root:root /home/UserName
chown root:root /home/UserName/ftpsite

5) Change the permission of user’s upload directory.
chown UserName:sftp upload

6) Set the group ‘sftp’ for the ‘UserName’.
usermod -g sftp UserName

7) Add the new user to SSH configuration
File: /etc/ssh/sshd_config

Configuration:

Subsystem sftp internal-sftp
AllowUsers UserName UserName1 UserName2
Match Group sftp

ChrootDirectory /home/%u/ftpsite
ForceCommand internal-sftp
AllowTcpForwarding no

8) Restart the SSH daemon.
/etc/init.d/sshd restart

Connect to FTP server and upload files to check the functionality.

Port: 22