To set up an SFTP server on Ubuntu or Debian, install OpenSSH Server, create a user, and verify the connection with sftp. SFTP runs through SSH on port 22 by default: you do not need to install a separate FTP daemon.
This tutorial covers two setups: a normal Linux account with SFTP access, and an optional SFTP-only, chroot-restricted account that can upload files but cannot open a shell or browse outside its assigned directory.
Windows has different installation steps, PowerShell commands and NTFS permissions. Follow the dedicated Windows 10/11 & Windows Server SFTP setup guide.
| Setup | Choose it when | Access |
|---|---|---|
| Standard OpenSSH SFTP | You manage your own Linux machine or trusted users. | Normal SSH account; file-transfer access wherever permissions allow. |
| SFTP-only chroot | You host restricted uploads for customers, vendors or applications. | Files under a restricted directory; no ordinary interactive shell. |
Step 1: Install and verify OpenSSH Server
Run these commands on the Ubuntu or Debian server that will receive files. Check whether OpenSSH is installed before adding anything else:
sudo apt update
sudo apt install openssh-server
sudo systemctl enable --now ssh
sudo systemctl status ssh --no-pager
Ubuntu and Debian normally use the service name ssh. Other distributions may call it sshd. If the server uses systemd socket activation, also inspect systemctl status ssh.socket.
Check the SFTP subsystem
OpenSSH supplies SFTP through an SSH subsystem. Most distributions configure it automatically. Inspect the relevant lines without modifying them:
sudo grep -RniE '^[[:space:]]*Subsystem[[:space:]]+sftp' \
/etc/ssh/sshd_config /etc/ssh/sshd_config.d/ 2>/dev/null
A typical entry uses /usr/lib/openssh/sftp-server, while Subsystem sftp internal-sftp is an alternative. Do not add a second SFTP subsystem directive when one already exists. The Subsystem directive is global; place it outside any Match block.
Allow the SSH/SFTP port
Both SSH and SFTP normally use TCP port 22. If UFW is active, confirm that the actual SSH port is allowed:
sudo ufw status verbose
# Only if the OpenSSH rule is needed:
sudo ufw allow OpenSSH
If SSH listens on another port, use that port instead. Also check any cloud firewall or provider security group. Keep your current administrator connection open when touching remote access rules.
active (running), and ss confirms that the SSH daemon is listening on port 22 for IPv4 and IPv6.Step 2: Create a user and test an actual upload
Create a dedicated test account on the server (or use an existing account with suitable access):
sudo adduser sftpuser
This creates a standard Linux account. Whether it can authenticate by password depends on your existing SSH policy. Do not enable global password authentication simply to get through this tutorial.
From a separate client computer, create a harmless test file and connect. For Linux/macOS clients:
printf 'SFTP upload check\n' > sftp-smoke-test.txt
sftp sftpuser@SERVER_IP
At the sftp> prompt, run the commands below. The file must exist on the client before put works:
pwd
ls
put sftp-smoke-test.txt
ls -l sftp-smoke-test.txt
get sftp-smoke-test.txt sftp-downloaded.txt
bye
Seeing sftp> shows the subsystem started. A successful put and get additionally confirm read/write access and a complete transfer. If the transfer fails but login succeeds, first inspect the target directory permissions.
For an alternate port use uppercase -P (unlike ssh -p); select a private key with -i:
sftp -P 2222 -i ~/.ssh/id_ed25519 sftpuser@SERVER_IP
put uploads a file, ls -l confirms it exists remotely, and get downloads it. This is a standard SFTP session, not the restricted chroot account demonstrated below.Step 3: Optional SFTP-only user with chroot
If the account only needs file transfers, use a Match Group rule to force internal SFTP and restrict its visible filesystem. A chroot is not necessary for trusted users who already have normal SSH access.
Create the group and assign the user
sudo groupadd --force sftpusers
sudo usermod -aG sftpusers sftpuser
id sftpuser
Make sure the output of id includes sftpusers. With this rule, every account in the group will receive SFTP-only restrictions on its next SSH connection. Do not add administrator accounts to this group.
Create a root-owned chroot and writable subfolder
sudo install -d -o root -g root -m 755 /sftp
sudo install -d -o root -g root -m 755 /sftp/sftpuser
sudo install -d -o sftpuser -g sftpusers -m 750 /sftp/sftpuser/uploads
namei -l /sftp/sftpuser/uploads
/sftp and /sftp/sftpuser must be owned by root and not group/other-writable. /uploads, inside the chroot, belongs to the SFTP user so uploads work. Avoid chmod 777 or making the chroot root writable.
Add the SSH Match rule
Edit /etc/ssh/sshd_config carefully, and place the block near the end of the file, after your global configuration. Keep the existing Subsystem sftp ... directive unchanged.
Match Group sftpusers
ChrootDirectory /sftp/%u
ForceCommand internal-sftp -d /uploads
DisableForwarding yes
PermitTTY no
%u expands to the authenticated account name. -d /uploads puts the SFTP session into the writable folder after entering the chroot. DisableForwarding blocks forwarding for matched accounts; PermitTTY no prevents allocating a terminal.
Configuration ordering matters: a Match block controls subsequent options until another Match or end of file. Do not inadvertently place global directives after it. On Debian/Ubuntu, include files in sshd_config.d may be read before the rest of the main file, so inserting a Match block into an early-loaded snippet without understanding ordering can cause confusing results.
Step 4: Validate, reload, and verify the restricted account
Before applying the new configuration, validate syntax and inspect the effective rules for this user. OpenSSH's -C option evaluates applicable Match rules:
sudo /usr/sbin/sshd -t
sudo /usr/sbin/sshd -T -C user=sftpuser,host=localhost,addr=127.0.0.1 \
| grep -Ei '^(chrootdirectory|forcecommand|disableforwarding|permittty) '
namei -l /sftp/sftpuser/uploads
Expect a chrootdirectory pointing to /sftp/%u and a forcecommand containing internal-sftp. A successful sshd -t prints nothing. The -T context is useful for debugging, but a successful real login is still necessary to verify permissions and authentication.
Keep your current administrative session open and reload the service rather than immediately restarting it:
sudo systemctl reload ssh
If your service does not support reload, consult its unit and arrange a controlled restart with console recovery available. From a separate computer, connect again:
sftp sftpuser@SERVER_IP
# At the sftp> prompt:
pwd
ls
put sftp-smoke-test.txt
bye
Inside the jail, the home location should resolve to /uploads if the -d setting applies. You should be able to upload but not traverse the host filesystem. A normal ssh sftpuser@SERVER_IP session should not give an interactive shell, although it may start and end the SFTP subsystem instead.
namei -l and sshd -T -C checks help confirm root-owned chroot parent directories and the effective SFTP-only Match configuration.Screenshot note: For the controlled local test, the SSH daemon ran only on 127.0.0.1:2222 with a separate configuration using ForceCommand internal-sftp (without -d /uploads). The test account therefore started at / and then ran cd uploads. With the example -d /uploads configuration above, the initial remote working directory should instead be /uploads.
127.0.0.1:2222, uploaded a file inside /uploads, and could not list /etc. This test used a separate SSH daemon, not the production SSH service.SSH keys and authentication for SFTP
SFTP uses SSH authentication. For an existing key pair you can connect with sftp -i ~/.ssh/id_ed25519 sftpuser@SERVER_IP. The matching public key must be authorized on the server and its file permissions must satisfy OpenSSH checks.
For a chrooted account with its normal home directory outside the jail, SSH public-key authentication ordinarily happens before the chroot is entered. The user's server-side authorized_keys can therefore remain in the account's regular home directory, assuming the effective AuthorizedKeysFile setting points there. Verify it with sshd -T -C when uncertain.
Test key-based login before tightening password authentication. See our SSH IdentityFile guide and authorized_keys guide.
Common SFTP server errors and fixes
| Symptom | What to check |
|---|---|
| Connection refused | systemctl status ssh, the actual listening port with ss -ltnp, and local/cloud firewall rules. |
| Permission denied (publickey) | Username, offered key, AuthorizedKeysFile, and ownership/modes of the key directories. |
| subsystem request failed | Single valid Subsystem sftp ... directive and available subsystem executable. |
| bad ownership or modes for chroot directory | namei -l /sftp/sftpuser: every path component must be appropriately root-owned and non-writable by other users. |
| Login works; upload fails | Write permission on /uploads inside the jail, not on the jail root. |
| Unexpected shell access | Group membership (id sftpuser) and effective forcecommand from sshd -T -C. |
sudo journalctl -u ssh -u sshd --since '15 minutes ago' --no-pager | tail -n 80
sudo /usr/sbin/sshd -t
sudo /usr/sbin/sshd -T -C user=sftpuser,host=localhost,addr=127.0.0.1 \
| grep -Ei '^(chrootdirectory|forcecommand|authorizedkeysfile) '
These checks are read-only. Do not disable security controls or restart the SSH daemon until the logs and effective configuration show what is wrong. For a failed upload, see SFTP Permission Denied.
Connect with a graphical SFTP client
Once the server passes the command-line test, any compatible SFTP client can connect using the same hostname, SSH port and credentials. ShadeTerm provides a graphical SFTP file manager alongside terminals and remote code editing in one server workspace.
For SFTP-only accounts, connect with the restricted username and verify the GUI client shows the chroot's /uploads folder. An SFTP client does not change the server's directory permissions or bypass the chroot configuration.
Linux, Windows, or a managed SFTP server?
This guide specifically configures a Linux server with OpenSSH. If the receiving machine runs Windows 10, Windows 11, or Windows Server, follow the dedicated Windows SFTP Server Setup. It covers Windows Optional Features, the sshd service, PowerShell, firewall rules and NTFS permissions.
A commercial managed SFTP server can make sense if you need centralized user management, enterprise reporting, compliance workflows or an administrative GUI. OpenSSH is a good free baseline when a server administrator can manage Linux accounts, permissions and security updates. Neither option makes the SFTP client and SFTP server interchangeable.
SFTP server setup FAQ
Is SFTP included with OpenSSH?
Yes. On a typical Ubuntu/Debian OpenSSH Server installation, the SFTP subsystem is already configured. Check the active Subsystem sftp directive before adding another one.
What port does an SFTP server use?
SFTP normally uses the SSH port, TCP 22 by default. A custom SSH port is also the SFTP port; with the sftp client, specify it using uppercase -P.
Can I create an SFTP-only account without an SSH shell?
Yes. Use Match with ForceCommand internal-sftp. Add ChrootDirectory when you also need filesystem isolation, and keep the chroot root-owned.
Does ChrootDirectory make a folder writable?
No. The chroot itself must not be writable by the matched user. Create a writable subdirectory, such as /uploads, inside the jail.
Should I restart SSH after changing SFTP settings?
Validate configuration with sshd -t, inspect matching rules with sshd -T -C, then use a supported reload procedure while keeping an administrator session and recovery access available.
How do I set up an SFTP server on Windows?
Windows uses a separate process for installing OpenSSH Server and setting NTFS permissions. See the Windows SFTP server guide rather than copying Linux chroot commands.
Technical references
- OpenSSH sshd_config(5) — SFTP subsystem, Match, ChrootDirectory, ForceCommand.
- OpenSSH sshd(8) — config validation and effective settings with
-T -C. - OpenSSH sftp(1) — client options and file-transfer commands.
- Ubuntu Server documentation: OpenSSH — Linux service and server setup.
Final check: verify transfers before granting access
For a basic Linux SFTP server, installing OpenSSH and testing an ordinary user may be all you need. For restricted users, verify ChrootDirectory permissions, the effective Match configuration and a real upload/download after reloading the daemon.
ShadeTerm can be used to browse the resulting SFTP server alongside SSH terminals, but the access rules and security enforcement remain on your server.
Try ShadeTerm when you want a graphical SFTP workflow.
