FTP is known as File Transfer Protocol, which is used to transfer files from server to server. It is a more secure and faster way of the file transfer. However, there is another protocol in this new era, which is much more secure than FTP, known as vsftpd (very secure file transfer protocol daemon). It is known for its performance, security, and stability. vsftpd is the default for many distributions of Linux and it offers strong security than the FTP server.
Ubuntu server 16.04 and a new user with the sudo privileges (it should not be the root user), then you can proceed with the below installation.
Installing vsftpd
sudo apt-get update
sudo apt-get install vsftpd
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.original
sudo ufw allow 20/tcp sudo ufw allow 21/tcp sudo ufw allow 990/tcp sudo ufw allow 40000:50000/tcp sudo ufw status
sudo adduser zehncloud
sudo mkdir /home/zehncloud/ftp
sudo chown nobody:nogroup /home/zehncloud/ftp
sudo chmod a-w /home/zehncloud/ftp
sudo ls -la /home/zehncloud/ftp
total 8
dr-xr-xr-x 2 nobody nogroup 4096 Sep 16 05:29 .
drwxr-xr-x 3 zehncloud zehncloud 4096 Sep 16 05:29 ..
Output
sudo mkdir /home/zehncloud/ftp/zt-data
sudo chown zehncloud:zehncloud /home/zehncloud/ftp/zt-data
sudo ls -la /home/zehncloud/ftp
total 12
dr-xr-xr-x 3 nobody nogroup 4096 Sep 16 05:35 .
drwxr-xr-x 4 zehncloud zehncloud 4096 Sep 16 05:35 ..
drwxr-xr-x 2 zehncloud zehncloud 4096 Sep 16 05:35 zt-data
Outpu
Allowing FTP Access to the User
Verify the vsftpd configuration file with the below configuration settings and make sure that every setting should match those below.
sudo nano /etc/vsftpd.conf
. . .
# Allow annonymous FTP?
annonymous_enable=NO
#
# Uncomment below line to allow local users to log in.
local_enable=YES
#
#Allow write access to ftp users.
write_enable=YES
#
#Uncomment the chroot to prevent the FTP user from accessing any files outside the directory tree.
chroot_local_user=YES
#
#add a user_sub_token option to insert the username into local_root directory path so that our #configuration will work for this user and all ftp users in future.
user_sub_token=$USER
local_root=/home/$USER/ftp
#
#To limit the range of ports for enough connections.
pasv_min_port=40000
pasv_max_port=50000
#
#The access is given to a user only when they are explicitly added into a list
#rather than by default:
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO
#Note: comment the above lines “userlist_enable” and “userlist_deny”, if the ftp services are not running.
. . .
/etc/vsftpd.conf
Create and add our user to the file.
echo "zehncloud" | sudo tee -a /etc/vsftpd.userlist
Check if the user has been added in the user list or not:
cat /etc/vsftpd.userlist
zehncloud
output
Testing FTP Access
As per the configuration, only the “zehncloud” user should be allowed to connect via FTP, and anonymous users should not be allowed to connect.
ftp -p 192.168.0.136
Connected to 192.168.0.136.
220 (vsftpd 3.0.3)
Name (192.168.0.136:default): test_user
530 Permission denied.
ftp: Login failed.
ftp>
Output
Close the connection
ftp -p 192.168.0.136
Connected to 192.168.0.136.
220 (vsFTPd 3.0.3)
Name (192.168.0.136:default): sudo_user
530 Permission denied.
ftp: Login failed.
ftp>
Output
Close the connection:
ftp -p 192.168.0.136
Connected to 192.168.0.136.
220 (vsFTPd 3.0.3)
Name (192.168.0.136:default): zehncloud
331 Please specify the password.
Password: your_user’s_password
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
Output
cd files
get test.txt
227 Entering Passive Mode (192,168,0,136,169,12).
150 Opening BINARY mode data connection for test.txt (16 bytes).
226 Transfer complete.
16 bytes received in 0.0101 seconds (1588 bytes/s)
ftp>
Output
put test.txt upload.txt
227 Entering Passive Mode (192,168,0,136,164,71).
150 Ok to send data.
226 Transfer complete.
16 bytes sent in 0.000894 seconds (17897 bytes/s)
Output
Close the connection:
bye
The above test confirms that our configuration is working fine.
In this tutorial, we have installed an FTP server and FTP user. Then we have configured their home directory and provide ownership to them. After that, we have allowed FTP access to the users and denied access to anonymous users. Finally, we have checked the FTP access to those users.