Monday, 31 May 2021

How to setup a FTP server in Ubuntu?

 Ref: https://www.techrepublic.com/article/how-to-quickly-setup-an-ftp-server-on-ubuntu-18-04/

The VSFTP daemon is found in the standard repositories, so installation can be pulled off with a single command. Open a terminal window and issue the following:

sudo apt-get install vsftpd

Start and enable the service with the commands:

sudo systemctl start vsftpd
sudo systemctl enable vsftpd

Once that installation completes, you're ready to continue.

Creating an FTP user

We're going to make this very easy and create a user for the FTP service that you can then give out to those who need it (and don't have a user account on the server). This could be considered an account for generic FTP usage. You can always create more, and anyone with a user account on the server can log via FTP. Our user will be called ftpuser and is created with the command:

sudo useradd -m ftpuser

Set the user's password with the command:

sudo passwd ftpuser

Your user is ready to go.

Configuring VSFTP

We're going to create a brand new configuration file. Before we do that, let's rename the original with the command:

sudo mv /etc/vsftpd.conf /etc/vsftpd.conf.orig

Create the new file with the command:

sudo nano /etc/vsftpd.conf

In that file, place the following:

listen=NO
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
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
pasv_enable=Yes
pasv_min_port=10000
pasv_max_port=10100
allow_writeable_chroot=YES

Logging in

At this point, you should be able to log into your FTP server using the ftpuser created earlier. Login with your favorite FTP GUI client or the command line. You can now upload and download files to your heart's content. Those files will be saved in the home directory of the ftpuser user (so /home/ftpuser). With our configuration file, we've disabled anonymous usage, so the only way to log in will be with a working account on the server.

Done and done

That's it. In about a minute, you've created an FTP server on Ubuntu 18.04. It really is that easy. Remember, however, this is pretty basic. The goal was to get it up and running quickly, so you might find it doesn't perfectly fit your needs. Fortunately, VSFTP is a fairly flexible server. To learn more about what this FTP server can do, issue the command man vsftpd.

No comments:

Post a Comment