In This blog we will see how to install and configure an FTP server on Ubuntu 20.04 that you use to share files between your devices.
FTP stand for File Transfer Protocol which is a standard network protocol used to transfer files to and from a remote system. We will be installing vsftpd which stand for Very Secure Ftp Daemon, a stable, secure, and fast FTP server.
FTP is a very popular protocol, for more secure and faster data transfers
Installing vsftpd on Ubuntu 20.04
The vsftpd package is available in the Ubuntu repositories. To install it, run the following commands:
sudo apt update
sudo apt install vsftpd
The ftp service will automatically start once the installation process is complete. To verify it, print the service status:
sudo systemctl status vsftpd
The output should show that the vsftpd service is active and running:
vsftpd.service - vsftpd FTP server
Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-03-02 15:17:22 UTC; 3s ago
.
.
.
Configuring vsftpd The vsftpd server configuration is stored in the /etc/vsftpd.conf
file.
For more visit the vsftpd documentation page.
In the following sections, we will go over some important settings needed to configure a secure vsftpd installation.
Start by opening the vsftpd configuration file:
sudo vi /etc/vsftpd.conf
Paste these properties at last
listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
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
user_sub_token=$USER
local_root=/home/$USER/ftp
pasv_min_port=30000
pasv_max_port=31000
userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
userlist_deny=NO
Save the file and restart the vsftpd service for changes to take effect:
sudo systemctl restart vsftpd
Opening the Firewall If you are running a UFW firewall , youll need to allow FTP traffic.
To open port 21 (FTP command port), port 20 (FTP data port), and 30000-31000 (Passive ports range), run the following commands:
sudo ufw allow 20:21/tcp
sudo ufw allow 30000:31000/tcp
To avoid being locked out, make sure port 22 is open:
sudo ufw allow OpenSSH
Reload the UFW rules by disabling and re-enabling UFW:
sudo ufw disable
sudo ufw enable
To verify the changes run:
sudo ufw status
Output look like
Status: active
To Action From
-- ------ ----
20:21/tcp ALLOW Anywhere
30000:31000/tcp ALLOW Anywhere
OpenSSH ALLOW Anywhere
20:21/tcp (v6) ALLOW Anywhere (v6)
30000:31000/tcp (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)
Creating FTP User
To test the FTP server, we will create a new user. Create a new user named newuser
:
sudo adduser newuser
Add the user to the allowed FTP users list:
echo "newuser" | sudo tee -a /etc/vsftpd.user_list
Create the FTP directory tree and set the correct permissions:
sudo mkdir -p /home/newuser/ftp
Give the require permission to the newuser.
sudo chmod 777 /home/newuser/ftp
sudo chown -R newuser: /home/newuser/ftp
Test your configuration Perform the following step in another windows/Linux system to test out
step 1: open Command line interface of your respective system and run this following command with replacing the ip_address
of remote system
ftp ip_address
Enter the user name which you newly created with password and you will see the following output
C:\Users\window>ftp 192.168.29.128
Connected to 192.168.29.128.
220 (vsFTPd 3.0.3)
200 Always in UTF8 mode. User (192.168.29.128:(none)): newuser
331 Please specify the password.
Password:
230 Login successful.
ftp>
Done!😎
Read the next blog to upload and download the file through the ftp
Top comments (0)