How to Install and Configure FTP Server in Ubuntu
Installing FTP
To enable FTP on your VPS, you will first need to install the VSFTPD package with the following command, before running the command update the sever to till date.
apt-get update
apt-get install vsftpd
Output:
root@vps:~# apt-get install vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
amd64-microcode intel-microcode iucode-tool
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
ssl-cert
Suggested packages:
openssl-blacklist
The following NEW packages will be installed:
ssl-cert vsftpd
0 upgraded, 2 newly installed, 0 to remove and 98 not upgraded.
Need to get 132 kB of archives.
After this operation, 398 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 ssl-cert all 1.0.39 [17.0 kB]
Once the installation is complete, We start the vsftpd service and enable it to start automatically at system boot.
systemctl start vsftpd
systemctl enable vsftpd
systemctl status vsftpd
Output:
root@vps:~# systemctl start vsftpd
root@vps:~# systemctl enable vsftpd
Synchronizing state of vsftpd.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable vsftpd
root@vps:~# systemctl status vsftpd
● vsftpd.service - vsftpd FTP server
Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled
Active: active (running) since Mon 2020-08-31 06:26:38 PDT; 2min 4s ago
Main PID: 13561 (vsftpd)
Tasks: 1 (limit: 2318)
CGroup: /system.slice/vsftpd.service
└─13561 /usr/sbin/vsftpd /etc/vsftpd.conf
Next, We open the FTP port on the system firewall to allow access to the FTP service from external systems.
ufw allow 20/tcp
ufw allow 21/tcp
ufw status
Output:
root@vps:~# ufw allow 20/tcp
Rule added
Rule added (v6)
root@vps:~# ufw allow 21/tcp
Rule added
Rule added (v6)
root@vps:~# ufw status
Status: active
To Action From
-- ------ ----
20/tcp ALLOW Anywhere
21/tcp ALLOW Anywhere
20/tcp (v6) ALLOW Anywhere (v6)
21/tcp (v6) ALLOW Anywhere (v6)
root@vps:~#
Configuring and Securing FTP Server
Before start the onfiguration of FTP server, first we will create a backup of the original config file /etc/vsftpd/vsftpd.conf
cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
Now,open the configuration file to configure the FTP
vi /etc/vsftpd.conf
Once enter the configuration file enable (uncomment)/modify the follwing parameters
Listen=yes
write_enable=YES
xferlog_std_format=YES
chroot_local_user=YES
listen_ipv4=no
Also, add the follwing parameters to the configuration file
allow_writeable_chroot=YES
userlist_file=/etc/vsftpd.userlist
Once configured the FTP restart thr vsftpd service
systemctl restart vsftpd
Testing FTP Server
Creating an FTP user and create a password for that user.
First, We add the user,
useradd -m -c "user1, Contributor" -s /bin/bash user1
Next, we setup a password for the user,
passwd user1
Output:
root@vps:~# useradd -m -c "user1, Contributor" -s /bin/bash user1
root@vps:~# passwd user1
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@vps:~#
Then, we have to add the created user to the file /etc/vsftpd.userlist by follwing command
echo "user1" | sudo tee -a /etc/vsftpd.userlist
cat /etc/vsftpd.userlist
Output:
root@vps:~# echo "user1" | sudo tee -a /etc/vsftpd.userlist
user1
root@vps:~# cat /etc/vsftpd.userlist
user1
root@vps:~#
Now we will test the FTP server is working or not
ftp <ftp server IP>
Output:
user1@vps:/root$ ftp <FTP server IP>
Connected to 104.200.67.173.
220 (vsFTPd 3.0.3)
Name (104.200.67.173:root): user1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls -al
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x 2 1000 1000 78 Aug 31 07:33 .
drwxr-xr-x 2 1000 1000 78 Aug 31 07:33 ..
-rw------- 1 1000 1000 53 Aug 31 09:05 .bash_history
-rw-r--r-- 1 1000 1000 220 Apr 04 2018 .bash_logout
-rw-r--r-- 1 1000 1000 3771 Apr 04 2018 .bashrc
-rw-r--r-- 1 1000 1000 807 Apr 04 2018 .profile
226 Directory send OK.
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS