Setup SFTP server on Ubuntu 22.04
This article will help you setup Secure File Transfer Protocol (SFTP) server on Ubuntu 22.04 using VSFTPD protocol and SSHD Secure service.

In this guide, we will show you how to setup a SFTP server using VSFTPD on Ubuntu 22.04 Focal Fossa.

VSFTPD is a popular choice for setting up FTP servers, and is the default FTP tool on a few Linux distributions. Follow the guide below to find out how to install the application and setup SFTP server up and running on Ubuntu 20.04.

VSFTPD installation

First, install VSFTPD on your system by typing this command into the terminal

sudo apt-get install vsftpd

Configure VSFTPD server

It’s always best practice to keep a backup copy of the original config file, just in case something goes wrong later. Let’s rename the default config file

sudo mv /etc/vsftpd.conf /etc/vsftpd.conf_bak

Create a new VSFTPD configuration file using nano or whichever text editor you prefer

sudo vi /etc/vsftpd.conf

Copy the following base configuration into your file. This configuration will suffice for a basic FTP server, and can later be tweaked for the specific needs of your environment once you’ve verified this is working properly


Paste the above lines into your newly created /etc/vsftpd.conf file, and then save changes and close the file.

Restart VSFTPD to apply the new changes

sudo systemctl restart vsftpd

Create an SFTP user

Our FTP server is ready to receive incoming connections, so now it’s time to create a new user account that we’ll use to connect to the FTP service

Use this first command to create a new account called ftpuser, and the second command to set a password for the account

sudo addgroup sftp 
sudo useradd -m sftpuser -g sftp
sudo passwd sftpuser

In order to verify that everything’s working properly, you should store at least one file in ftpuser‘s home directory. This file should be visible when we login to FTP in the next steps

sudo bash -c "echo FTP TESTING > /home/sftpuser/FTP-TEST"

Secure VSFTPD connection using SSH

FTP is a great protocol for accessing and transferring files, but it has the shortcoming of being a clear text protocol. In other words, it’s not secure to use over an internet connection, since your credentials and data are transmitted without encryption. The ‘S’ in SFTP stands for ‘Secure’ and tunnels the FTP protocol through SSH, providing the encryption needed to establish a secure connection.

SFTP requires SSH, so if SSH server is not already installed on your system, install it with the following command

sudo apt install ssh

Once SSH is installed, we need to make some changes to the SSHD configuration file. Use nano or your favorite text editor to open it

sudo vi /etc/ssh/sshd_config

Scroll to the bottom of the file and add the following 5 lines at the very end

Match group sftp
ChrootDirectory /home
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

The lines above will allow users in the sftp group to access their home directories via SFTP, but denies them normal SSH access, so they can never access a shell. After pasting those lines, save and close the configuration file

Change FTP default port number

By default FTP protocol works on TCP port 20 and 21, if you would like to change it any other port number of your choice like 5678, modify the following line in file /etc/ssh/sshd_config

Port 5678

Save and close the file.

Restart SSH daemon

sudo service sshd restart

Change Default Directory for SFTP home

Also if you would like to change the default directory of sftpuser, open the following file

sudo vi /etc/passwd

Search for the ftpuser in the file


Where xxxx is uid of ftpuser and yyyy is group id of the sftpuser.

That’s it you are done !

Also to refer similar articles on Ubuntu and wordpress visit the following page

Similar Posts

  • All
  • ubuntu
  • apache2
  • Plex
  • raspberrypi
  • ssl
  • deluge
  • torrent
Nextcloud Logo

Mobeen Syed on October 3, 2022

Setup Nextcloud on Ubuntu 20.04 using Apache2, PHP LAMP stack, SSL secure with letsencrypt and fail2ban brute force protection using fail2ban.

Mobeen Syed on October 3, 2022

Installation and Setup of Fail2ban Brute force protection on Nextcloud, SSH, FTP etc on Ubuntu or other debian based distributions.

Mobeen Syed on September 9, 2021

Network Wide Block Advertistment, Pornography and Adult Content with AdGuard Home Installed on Raspberry Pi or Ubuntu Server

Leave a Reply

Your email address will not be published. Required fields are marked *