Monday, June 18, 2018

Install and configure FTP and SFTP in Centos

Description: Here I have explained how to configure FTP and SFTP in centos

Procedure:

Setup FTP on Centos 
  • Enable epel repository by using below command

[root@localhost ~] # wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-6.noarch.rpm

[root@localhost ~] # rpm -ivh epel-release-7-6.noarch.rpm
  • Install ftp by using below command
[root@localhost ~] # yum install vsftpd
  • Open /etc/vsftpd/vsftpd.conf to configure ftp server. Made below changes in server
[root@localhost ~] # vi /etc/vsftpd/vsftpd.conf

anonymous_enable=NO
local_umask=022
chroot_local_user=YES  #(this property used to limit the users to their home directories.)
local_enable=YES
write_enable=YES
  • Enable and start service

[root@localhost ~] # systemctl start vsftpd
[root@localhost ~] # systemctl enable vsftpd
  • Verify installation by browse ftp://IP_ADDR
Setup SFTP on Centos 

Description: SFTP is the FTP service built into Secure Shell [SSH]

  • SFTP Directory: The First thing you need to create a directory to host your FTP data.
# mkdir /data
# chmod 701 /data
  • Create SFTP user and group: Now we are creating user and group to access ftp 
# groupadd sftp_users
# useradd -g sftp_users -d /data -s /sbin/nologin USERNAME

Where USERNAME is the name of user. Now set password to user 

# passwd USERNAME

  • Create new user SFTP directory: We will create new directory to store data and assigned permission to user. 
# mkdir -p /data/USERNAME/upload
# chown -R root:sftp_users /data/USERNAME
# chown -R username: sftp_users /data/USERNAME/upload
  • Configure sshd configuration file and add below content to the end of file.
# vi /etc/ssh/sshd_config
Match Group sftp_users
ChrootDirectory /data/%u
ForceCommand internal-sftp

  • Save and close file. Restart ssh service for effect.
# systemctl restart sshd
  • Check user by login using sftp USERNAME@IP_ADDR

No comments:

Post a Comment