centos enable ftp service code example

Example: how to enable ftp on centos 7

sudo yum update
sudo yum install vsftpd

sudo systemctl start vsftpd

//to start the server on boot
sudo systemctl enable vsftpd

//to allow trafic to port 21
sudo firewall-cmd --zone=public --permanent --add-port=21/tcp
sudo firewall-cmd --zone=public --permanent --add-service=ftp
sudo firewall-cmd –-reload

//Configuration

//to copy the config file
sudo cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.default

//to exit the config file in nano editor you can use vi too
sudo nano /etc/vsftpd/vsftpd.conf

//find the 2 entries and edit them to the given below
anonymous_enable=NO
local_enable=YES
local_enable=YES
chroot_local_user=YES   //Lmit FTP users to their own home directory.
allow_writeable_chroot=YES

userlist_enable=YES
userlist_file=/etc/vsftpd/user_list
userlist_deny=NO

//after editing the file save it and restart the server
sudo systemctl restart vsftpd

//create new ftp user
sudo adduser testuser
sudo passwd testuser

//add user to user list
echo “testuser” | sudo tee –a /etc/vsftpd/user_list

//create directory for new user and adjust permissions
sudo mkdir –p /home/testuser/ftp/upload
sudo chmod 550 /home/testuser/ftp
sudo chmod 750 /home/testuser/ftp/upload
sudo chown –R testuser: /home/testuser/ftp

//now run tyour ftp
ftp localhost