Install and Configure SFTP

SFTP(Secure File Transfer Protocol) provides a secure way for file transfer between hosts. It is FTP that runs over SSH(Secure Shell). It runs on the port number which SSH is assigned to. It can be launched either through graphical or command-line.

In the article we shall focus on the command-line in Cent OS.

Firstly we must make sure ssh-server is installed.

rpm -q openssh-server  It checks if  ssh server is already installed.

yum install -y openssh-server Installs the ssh server.

Create a new group of sftp users or give it any name you can prefer

groupadd sftpusers

 

We can check the group gid(group id)

grep sftpusers /etc/groups

We need to comment line containing /usr/libexec/openssh/sftp-server by adding a # at the beginning of the line.

And add the following after in Subsystem sftp internal-sftp

Add user with ftp access group giving the sftpusers as the primary group
adduser testuser --gid 1002 --shell /usr/sbin/nologin

Give testuser password
passwd testuser

Modify the home directory permissions
chown root:root /home/testuser

Create folder inside the testuser folder
mkdir -p /home/testuser/files

Change the permission of the files folder

Now you check ssh service status
service sshd status

Start ssh service
service sshd start

On the client side you can connect to the server
sftp [email protected][server-ip]

Leave a Reply

Your email address will not be published.