How To Setup FTP Server In Linux/Unix?
What is FTP?
FTP is the short form of File Transfer Protocol. It is a standard networking protocol used to transfer files between client and server. An FTP user may authenticate themselves by using username and a password. For secure transmission of username or password or other encrypted content that is to be transferred, FTP is often secured with the SSL/TLS(FTPS) or replaced with SSH File Transfer Protocol(SFTP). FTPD, VSFTPD, PROFTPD, and PUREPTPD are some examples of FTP servers used in Unix or Unix based systems.
What is vsftpd?
VSFTPD stands for “Very Secure File Transfer Protocol Daemon”. Using FTP without including any type of security layers likes SSL/TLS is insecure, and anyone should avoid this because it transmits data without encryption. So It is recommended to use a secure version of FTP such as SFTP. In this article, we are going to discuss about installing and configuring vsftpd which is a type of secure FTP server.
Installing vsftpd –
To install vsftpd in your system use the following commands(In debian based systems) –
sudo apt-get update
sudo apt-get install vsftpd
Enable vsftpd services –
Start the vsftpd services by using the given command-
systemctl start vsftpd
systemctl enable vsftpd
Create an FTP directory and grant required permissions –
So before starting, we need to create a user for FTP access-
sudo adduser testuser
Next, create an FTP directory and set ownership by using the given command-
sudo mkdir /home/testuser/ftp
sudo chown nobody:nogroup /home/testuser/ftp
sudo chmod a-w /home/testuser/ftp
Now create a directory where files can be uploaded by testuser –
sudo mkdir /home/testuser/ftp/test
sudo chown testuser:testuser /home/testuser/ftp/test
Configure vsftpd server –
The configuration of vsftpd is saved in a file called vsftpd.conf which resides inside /etc/ directory of the system. For the secure implementation of the vsftpd server, we have to add/modify some options inside the vsftpd configuration file. But before making any changes to the configuration file, It is good to take the backup of the original file. The same can be done by using the given command-
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
Now open the configuration file by using a text editor-
sudo nano /etc/vsftpd.conf
And add or uncomment the following options that are given inside the vsftpd.conf file –
listen=YES listen_ipv6=YES anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES use_localtime=YES xferlog_enable=YES connect_from_port_20=YES chroot_local_user=YES secure_chroot_dir=/var/run/vsftpd/empty pam_service_name=vsftpd pasv_enable=Yes pasv_min_port=10000 pasv_max_port=11000 user_sub_token=$USER local_root=/home/$USER/ftp userlist_enable=YES userlist_file=/etc/vsftpd.userlist userlist_deny=NO
Save the edited file by pressing ctrl+o followed by the return key. The options in the configuration file can be added or modified according to your needs.
Now we need to add testuser into
/etc/vsftpd.userlist file to allow FTP access. Use the following command to open the file using a text editor –
sudo nano /etc/vsftpd.userlist
Now add the testuser in this file and press ctrl+s to save and ctrl+x to exit from the editor.
Restart the vsftpd services –
sudo systemctl restart vsftpd
To check the status of FTP server use the following command –
sudo systemctl status vsftpd
As you can see in the image server is active(running). Now it is ready for use.
Accessing FTP server –
The FTP server can be accessed by using a web browser or an FTP client application like Filezilla. To access from web browser use the URL of the site like ftp://example.com or use the localhost IP address if your FTP server is running locally. For example – Enter ftp://127.0.0.1 in your browser and press enter it will ask you to enter username and password. Enter the username that you have created before, and password and press enter to proceed. It will display the files and directories of the system. You can enable the SSL/TLS to encrypt the data transferred via FTP.
I hope this will gives you a basic understanding of implementing the FTP server in your system. At any step, if you find yourself stuck feel free to write us in the comments below.
You might also like
Sometimes you wanted to change the Hostname on a Linux machine like on your Ubuntu PC or a Fedora machine or any other Linux distro like a Citrix XenServer to
I already discussed briefly about Aptitude which is a debian package manager. In this article, we will see it in more detail and also we will discuss how can we
Introduction to firewall A firewall is a network security system that monitors incoming and outgoing network traffic and allows or blocks the data packets based on a set of security