# Installing FTP Server (VSFTPD) on Ubuntu 22.04

An FTP (File Transfer Protocol) server in Linux is a service that allows users to transfer files between computers over a network. FTP servers are commonly used for uploading and downloading files, and they can be accessed via various FTP client applications.

### Key Features of an FTP Server:

1. **File Transfer**: Facilitates the upload and download of files between clients and the server.
    
2. **Authentication**: Users can authenticate with a username and password, allowing controlled access to files.
    
3. **Directory Listing**: Users can view and navigate through directories on the server.
    
4. **File Management**: Supports operations like renaming, deleting, and moving files.
    
5. **Passive and Active Modes**: FTP can operate in active or passive mode, affecting how connections are established.
    

**<mark>Step 1: Install VSFTPD Server</mark>**

First, open your terminal and execute the following commands to install VSFTPD:

```plaintext
sudo apt update
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726903543725/4546d529-db4e-4ff0-ab74-2f0e8c6bfeef.png align="center")

```plaintext
sudo apt install vsftpd -y
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726903579902/2570cd06-b733-4884-a764-8b98df6a5fb0.png align="center")

Once installed, check the status of the VSFTPD service:

```plaintext
sudo service vsftpd status
```

This command ensures that the VSFTPD server is running correctly.

**<mark>Step 2: Configure Firewall</mark>**

To allow FTP connections, configure your firewall settings. Execute these commands:

```plaintext
sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
sudo ufw allow 40000:50000/tcp
sudo ufw allow 990/tcp
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726916535865/f2f64657-c29b-4d35-a7c4-0663873a98ff.png align="center")

These commands open the necessary ports for FTP communication.

**<mark>Step 3: Create an FTP User</mark>**

Next, create a dedicated FTP user to manage file uploads and downloads. Run the following commands:

```plaintext
sudo adduser ftpuser
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726916846403/84b1fb61-56bc-4073-bc64-7289175fe2b9.png align="center")

```plaintext
sudo mkdir /home/ftpuser/ftp
sudo chown nobody:nogroup /home/ftpuser/ftp
sudo chmod a-w /home/ftpuser/ftp
sudo mkdir /home/ftpuser/ftp/files
sudo chown ftpuser:ftpuser /home/ftpuser/ftp/files
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726916934749/e9447196-7af9-410b-84bd-c4ff91f0d550.png align="center")

This setup creates a user directory structure that restricts write permissions for the main FTP directory.

**<mark>Step 4: Configure VSFTPD</mark>**

Backup the original configuration file before making changes:

```plaintext
 sudo mv /etc/vsftpd.conf /etc/vsftpd.conf.origin
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726917607802/e51e30aa-7571-48dc-8fb4-7d8453b6d5cb.png align="center")

Now, open the VSFTPD configuration file:

```plaintext
sudo nano /etc/vsftpd.conf
```

Modify or add the following settings to the file:

```plaintext
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
force_dot_files=YES
pasv_min_port=40000
pasv_max_port=50000

user_sub_token=$USER
local_root=/home/$USER/ftp
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726917777676/e58fd902-7454-4e27-97e6-7e243a01a517.png align="center")

After saving the changes, restart the VSFTPD service to apply the new configuration:

```plaintext
sudo systemctl restart vsftpd.service
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726917830028/d4b8b051-8b8f-4498-9bc5-e2ca078dbc91.png align="center")

**<mark>Step 5: Test FTP Connection</mark>**

Log in to your client machine and run:

```plaintext
ftp ftp-server-ip
```

Replace `ftp-server-ip` with your server’s actual IP address. Log in with the `ftpuser` credentials you created earlier. If you connect successfully, your FTP server is ready for use!

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726918085299/c151a0ae-50a0-4448-a4c2-429db31a5d6c.png align="center")

#### Using WinSCP as a GUI FTP Client

1. * Open the WinSCP after installation.
        
2. **Configure the Connection**:
    

In the **Login** dialog, enter the following details:

**File Protocol**: Select `FTP` &gt; **Host name**: Enter your server’s IP address &gt; **Port number**: Enter `21` (default FTP port) &gt; **User name**: Enter the FTP user you created (e.g., `ftpuser`) &gt; **Password**: Enter the password for the FTP user

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726918327489/2beaa3cc-3940-4e62-85e5-a29a85f420f2.png align="center")

You should now be connected successfully!

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726918464975/403636f0-847c-4a1d-b487-cc190994ba07.png align="center")

### Conclusion

Setting up a VSFTPD server on Ubuntu is straightforward and provides a secure method for file transfer. With this guide, you can now manage your FTP server effectively. If you have any questions or comments, feel free to reach out!
