How to Set Up an FTP Server on Linux
- CloudCastHub
- Aug 12, 2024
- 3 min read
Setting up an FTP server on Linux is key for sharing files safely across devices. FTP lets you move files between a client and server over a network. This guide will show you how to set up an FTP server on Linux, using Debian as the example.
Introduction to FTP
FTP is an old but widely used way to move files over networks. It uses a client-server model. The client starts the connection, and the server sends or gets files.
Even though SFTP is better for security, FTP is still used for its ease and speed. It’s good for local networks or controlled places.
How FTP Works: Client-Server Architecture
FTP uses a client-server setup. It has two connections: a control connection and a data connection. The control connection sets up the link between the client and server. It lets the client send commands and get responses.
The data connection is for moving files. FTP can work in active mode or passive mode. The choice depends on the network and firewall settings for reliable transfers.
FTP uses TCP for reliable data transfer. TCP checks for errors and sends data again if needed. This makes sure files are transferred correctly.
Step 1: Installing the FTP Server Software
To start, you need to install FTP server software. `vsftpd` is a top choice for a secure FTP server on Linux.
Installation on Debian
First, update your package list with `sudo apt update`.

Then, install vsftpd with `sudo apt install vsftpd`. This installs the FTP server and all its necessary dependencies.

Step 2: Configuring the FTP Server
After installing `vsftpd`, you must set it up for your needs.
Editing the Configuration File
The vsftpd config file is at “/etc/vsftpd.conf”. Back up the original file with `sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak`.

Open the file for editing with `sudo nano /etc/vsftpd.conf`.
Key Configuration Settings
1. Enable Local User Login:
Uncomment the line local_enable=YES to allow local users to log in.

2. Allow FTP Write Operations:
Uncomment the line write_enable=YES to allow users to upload files.

3. Restrict Users to Their Home Directories:
For security reasons, it’s advisable to restrict users to their home directories. Uncomment the line chroot_local_user=YES.

4. Allow Writable Chroot:
If you need to allow writable chroot, which enables users to write to their home directory even when restricted to it, add the line allow_writeable_chroot=YES at the end of the configuration file.

After making these changes, restart the `vsftpd` service to apply the new configuration using `sudo systemctl restart vsftpd`.

Step 3: Creating FTP Users
It’s smart to create special FTP users for better security and control.
Adding a New FTP User
Create a new user with `sudo adduser ftpuser`. Set a password and details for the user.

Make a directory for FTP files with `sudo mkdir /home/ftpuser/ftp`.

Change the ownership with `sudo chown nobody:nogroup /home/ftpuser/ftp`.

Remove write permissions with `sudo chmod a-w /home/ftpuser/ftp`

Step 4: Securing the FTP Server
FTP isn’t secure by default. To secure it, enable SSL/TLS.
Enabling SSL/TLS
First, make an SSL certificate with `sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem`.

Then, open the vsftpd config file with `sudo nano /etc/vsftpd.conf`

Change these lines to turn on SSL/TLS:
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
rsa_cert_file=/etc/ssl/private/vsftpd.pem
Restart vsftpd to make the changes with `sudo systemctl restart vsftpd`.

Step 5: Testing the FTP Server
After setting up and securing your FTP server, it’s important to test it.
Connecting with an FTP Client
Use an FTP client like FileZilla or the command line with ftp localhost to test. Log in with the FTP user details you set up.

Try uploading and downloading files to the /ftp directory.

Verifying SSL/TLS
Make sure your FTP client uses SSL/TLS. Check the connection is secure by seeing if the client shows it’s secure.
Conclusion
Setting up an FTP server on Linux means installing and configuring the server, creating users, and securing it with SSL/TLS. Follow these steps to set up a secure FTP server for sharing files. FTP is good but consider more secure options like SFTP when you can.
FAQ
What is FTP (File Transfer Protocol)?
FTP is a network protocol for safely moving files over the internet. It uses FTP servers to let users upload, download, and manage files in one place.
How does FTP work?
FTP uses a client-server setup with two channels: control and data. The control channel links the client and server for commands and responses. The data channel sends the files between them.
What is an FTP server?
An FTP server is a system or service for storing and transferring files online. It's where users can upload, download, and manage their files from anywhere.
How do I connect and use an FTP server?
To connect, users can use the command line, web browsers, or FTP clients. Once in, FTP lets users manage files, upload, download, and set permissions.
Comments