Guide
How to set up an SFTP server on Windows and Linux (OpenSSH)
An SFTP server is an SSH server: install OpenSSH Server, start the sshd service and allow TCP port 22, and SFTP works for every account on the machine. On Windows 10 and 11 it's a free optional feature; on Linux it's the openssh-server package.
Below: installing it on both, checking SFTP is on, and giving someone an SFTP-only account that's locked into one folder with no terminal. Weighing SFTP against FTP? See SFTP vs SCP vs FTP, or set up an FTP server on Windows for devices that only speak FTP.
- OpenSSH Server
- Windows and Linux
- SFTP-only users
Updated · OpenSSH Server on Windows 10 and 11, Ubuntu, Debian, Fedora and RHEL
Install an SFTP server on Windows 10 and 11
Step 1: Add OpenSSH Server
Open Settings > System > Optional features (on Windows 10, Apps > Optional features), choose View features or Add a feature, and add OpenSSH Server. Or in PowerShell as administrator:
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*' Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Step 2: Start sshd, now and at every boot
Start-Service sshd Set-Service -Name sshd -StartupType Automatic
Step 3: Check the firewall rule
Installing it adds a rule for port 22. Check it's there and on:
Get-NetFirewallRule -Name *OpenSSH-Server* | Select-Object Name, Enabled # If it's missing: New-NetFirewallRule -Name sshd -DisplayName "OpenSSH Server (sshd)" -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow
Step 4: Connect
From another computer,
sftp yourname@windows-pcwith your Windows user name and password. You start in your user folder. The server's settings are inC:\ProgramData\ssh\sshd_config; runRestart-Service sshdafter changing them.
Keys for administrator accounts
C:\ProgramData\ssh\administrators_authorized_keys, not in the user's own .ssh folder. Passwordless SSH with keys covers both.Install an SFTP server on Linux
Install OpenSSH Server, start it now and at boot, and allow SSH in the firewall:
# Ubuntu and Debian sudo apt update && sudo apt install -y openssh-server sudo systemctl enable --now ssh sudo ufw allow OpenSSH # Fedora, RHEL, Rocky Linux and AlmaLinux sudo dnf install -y openssh-server sudo systemctl enable --now sshd sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload
SFTP is on by default. To check, look for the Subsystem sftp line in /etc/ssh/sshd_config; if it's commented out, remove the # and restart SSH. For the details of turning SSH on, including on a Raspberry Pi and Ubuntu's newer socket activation, see how to enable SSH on Ubuntu and Debian.
Add SFTP-only users (no terminal, one folder)
For people who only need to upload and download, such as a customer, a scanner or a backup job, lock their account to SFTP inside a folder of its own. On Linux, make a group for them and an account with no shell:
sudo groupadd sftponly sudo useradd -m -G sftponly -s /usr/sbin/nologin uploader sudo passwd uploader
Add this at the end of /etc/ssh/sshd_config:
Match Group sftponly
ChrootDirectory /srv/sftp/%u
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding noThe folder they're locked into must belong to root and not be writable by anyone else, so give them a folder inside it to write to, then check the settings and restart SSH:
sudo mkdir -p /srv/sftp/uploader/files sudo chown root:root /srv/sftp/uploader sudo chmod 755 /srv/sftp/uploader sudo chown uploader:uploader /srv/sftp/uploader/files sudo sshd -t && sudo systemctl restart ssh # sshd on Fedora and RHEL
On Windows, the same idea works for SFTP sessions. Add this at the end of C:\ProgramData\ssh\sshd_config:
Match User uploader
ChrootDirectory C:\SFTP\uploader
ForceCommand internal-sftp
AllowTcpForwarding noThen Restart-Service sshd. Give the user write access only to a folder inside it, for example with icacls C:\SFTP\uploader\files /grant "uploader:(OI)(CI)M".
Test it
sftp uploader@server should land in / and show only the files folder, and ssh uploader@server should refuse a terminal.Make it safe before you rely on it
- Sign in with keys, and turn password sign-in off for everyone who can use keys: passwordless SSH with keys.
- Give each person their own account, so you can remove one without changing everyone's password.
- Keep the server updated. Moving it off port 22 cuts down noise in the logs but isn't protection on its own: the SSH port.
- Don't forward port 22 on your router unless you have to. On a home or office network, RemoteAccessApp can reach the server through one of your own PCs there instead.
Connect with RemoteAccessApp
In the RemoteAccessApp Console, add the server on Connections as an SFTP host (or as an SSH host and click Files). The first time, you see the server's key fingerprint and choose whether to trust it. Its files open next to your PC's in two panes, with drag and drop both ways, and you can copy straight from one server to another. Free on Windows and Linux for up to 5 saved hosts: download RemoteAccessApp. Comparing clients first? Use the SSH client checklist.
Questions, answered
Related
- How to use SFTPConnect with sftp, move files with get and put, look up any common sftp command, and choose between SFTP, scp and rsync.Read the guide
- SFTP vs SCP vs FTPSFTP, SCP, FTP and FTPS side by side: what each one is, the ports they use, the commands, and which to pick for a job.Read the guide
- Enable SSH on UbuntuInstall and start the SSH server on Ubuntu or Debian, let it through the firewall, check it's listening and connect. Plus OpenSSH Server on Windows 11.Read the guide
- Passwordless SSH with keysMake an SSH key, copy it to the server with ssh-copy-id (or one PowerShell line on Windows), get the permissions right and sign in without a password.Read the guide
- FTP server on WindowsWindows has an FTP server built in. Turn on IIS FTP, add a site and a user, open the firewall, add TLS, then connect from another PC.Read the guide
- SSH & SFTP clientTerminal tabs, an SFTP and FTP file manager, key sign-in and one command to every server.Learn more
