Save 10%Pay yearly on any plan. 6% half-yearly, 3% quarterly. Help centreWhatsAppTelegram TeamsOpen a ticket

How to Set Up a File Transfer Server on Ubuntu: FTP or SFTP?

Before installing an FTP server on Ubuntu, decide between FTP and SFTP. How they differ, and how to set up upload-only SFTP users locked into their own folder.

2 min readBy Shailabh

Reviewed by the AmazingRDP technical team

Setting up an FTP or SFTP server on Ubuntu

Need a server to exchange files with customers or colleagues? A Linux VPS gives you root access and a public IP address. See Linux VPS from $6.99

"I need an FTP server" usually means "people must be able to upload and download files". On Ubuntu there are two ways to give them that, and the better one is already installed.

FTP or SFTP?

FTP (with TLS)SFTP
Software on the serverAn extra program, usually vsftpdNone; part of the SSH server
Ports to open21 plus a range for transfers22 only
EncryptionMust be switched on and configuredAlways
Login with keysNoYes
Works withEvery FTP program, old devices, some cameras and scannersFileZilla, WinSCP, Cyberduck, every current tool

Choose SFTP unless a device or program can only speak FTP. Despite the names, the two are unrelated protocols.

If you need real FTP, our step-by-step guide covers vsftpd with encryption, passive ports and the usual errors: how to enable FTP on Ubuntu. The rest of this page sets up SFTP the way an FTP server is normally wanted: users who can transfer files and do nothing else.

SFTP-only users, locked into their folder

1. A group for these users:

sudo groupadd sftponly

2. A user without a shell:

sudo useradd -m -g sftponly -s /usr/sbin/nologin client1
sudo passwd client1

3. The folder rules. The folder a user is locked into must belong to root and must not be writable by anyone else; this is a requirement of the SSH server. The user gets a writable folder inside it:

sudo chown root:root /home/client1
sudo chmod 755 /home/client1
sudo mkdir /home/client1/files
sudo chown client1:sftponly /home/client1/files

4. Tell the SSH server. Create a settings file:

sudo nano /etc/ssh/sshd_config.d/sftponly.conf
Match Group sftponly
    ChrootDirectory %h
    ForceCommand internal-sftp
    AllowTcpForwarding no
    X11Forwarding no

5. Check and reload:

sudo sshd -t
sudo systemctl reload ssh

sshd -t prints nothing when the settings are correct. Keep your own session open while you test with a second one.

Test

sftp client1@203.0.113.10

The user lands in a folder that looks like / and contains only files. An attempt to log in with ssh is refused. In FileZilla or WinSCP, choose the protocol SFTP and port 22: see our WinSCP guide.

More users

Repeat steps 2 and 3 for each. The settings file covers the whole group.

If login fails

SignCause
Connection closes right after the passwordThe locked folder is not owned by root, or is writable by group or others. Look in sudo journalctl -u ssh -n 20 for "bad ownership or modes"
Permission denied on uploadThe user is writing to the locked folder itself; uploads go into files
The user can still open a shellThe user is not in the group, or the settings file is not loaded

Keep it safe

  • Allow port 22 for known addresses where you can: see open or block a port in the Ubuntu firewall.
  • Use keys in place of passwords for users who can handle them.
  • Watch disk space; an upload folder fills a server quietly.

Our Linux VPS plans come with SSH, and so with SFTP, from the first minute. For sharing inside an office network, see NFS or Samba.

Questions

What is the difference between FTP and SFTP?

They are different protocols. SFTP runs over SSH on port 22 and is always encrypted. FTP is older and needs extra software and ports.

Do I need to install anything for SFTP on Ubuntu?

No. It is part of the OpenSSH server that Ubuntu Server already runs.

How do I restrict an SFTP user to one folder?

Use ChrootDirectory and ForceCommand internal-sftp in a Match block of the SSH server settings.

Why does my chrooted SFTP user get disconnected?

The folder the user is locked into must be owned by root and not writable by anyone else.