Friday, 16 June 2017

SFTP Server installation and configuration in Linux

SFTP installation and  configuration in linux  :-



File Transfer Port : 22
Server  : 10.1.1.2
Configuration  file  : /etc/ssh/sshd_config

SFTP is used for transfer the files through 22 port. Using SFTP securely transfer the files between servers. SFTP user created with ‘nologin’ so SFTP user can only able to transfer the file and not able to do any other activities like server login etc.

Steps :-
Create the group for SFTP users
#groupadd   sftp_users
Create the user associate with SFTP user and nologin
#useradd   -G    sftp_users   -d  /home/testuser  -s  nologin  testuser

G – add the user to secondary group
d  -  create the user with particular directory
s  -  create the user with particular shell
Open the ‘sshd_config’ configuration file and do below changes.
#vi /etc/ssh/sshd_config
Comment below line
#Subsystem       sftp    /usr/libexec/openssh/sftp-server
Add below lines
Subsystem       sftp    internal-sftp
Match Group sftp_users
X11Forwarding no
AllowTcpForwarding no
ChrootDirectory %h
ForceCommand internal-sftp
wq!
Save& quit the file
From above
Match Group  : This indicates added lines in ‘sshd_config’  matched only for the uses belongs to that group(sftp_users).
ChrootDirectory  : This represent the home directory of the user.
ForceCommand internal-sftp  :  This force the execution of the internal-sftp and ignores any commands that are mentioned in  ~/.ssh/rc file.
Restart the sshd service
#service sshd restart
#chkconfig sshd on
Set the permissions:
#chmod  755  /home/ testuser
#chown  root  /home/ testuser
#chgrp  – R sftp_users  /home/ testuser

User wants to upload the files please follow the below steps:
#mkdir  /home/ testuser/upload
#chown   testuser .   /home/ testuser/upload

Connect to the SFTP
Connect to the SFTP and upload the files

Using  put command upload the files to the directory

No comments:

Post a Comment