How to enable sftp server in ubuntu a comprehensive guide — this quick guide will show you how to set up SFTP on Ubuntu so you can securely transfer files without exposing your SSH shell to users. If you’re a sysadmin, developer, or just someone who wants a safe file-transfer workflow, you’re in the right place. Below is a practical, step-by-step approach with tips, common pitfalls, and best practices.
Quick fact: SFTP SSH File Transfer Protocol runs over SSH and provides encrypted file transfer, authentication, and integrity checks. In this guide, you’ll learn how to enable and configure an SFTP server in Ubuntu, with user isolation, secure access, and helpful maintenance steps. We’ll cover:
- Prerequisites and installation
- Basic vs. chrooted sftp-only configurations
- User management and permissions
- Security hardening tips
- Troubleshooting and practical examples
Useful resources you might want to check later text only:
- Ubuntu Official Documentation – ubuntu.com
- OpenSSH Portable – openssh.com
- SSH Hardening Best Practices – cisecurity.org
- Linux Security – linuxsecurity.com
- How to secure SSH with Key-based authentication – digitalocean.com
Prerequisites and what you’ll need
- A Ubuntu server 22.04 LTS or newer recommended
- Root or sudo privileges
- A basic understanding of SSH and Linux file permissions
- OpenSSH already installed or available to install
Step 1: Install OpenSSH Server if not already installed
- Check if SSH is installed: sudo systemctl status ssh
- Install if missing: sudo apt update && sudo apt install -y openssh-server
- Enable and start: sudo systemctl enable ssh && sudo systemctl start ssh
- Verify the service: sudo systemctl status ssh
Tip: If you’re using a cloud provider, ensure the security group or firewall allows port 22 or your custom SSH port.
Step 2: Decide between standard SSH access or SFTP-only chrooted access
Two common setups:
- Standard SSH access with SFTP subsystem
- SFTP-only with chroot jail no SSH shell for SFTP users
Why choose SFTP-only? It’s a safer environment when you want to give users file transfer capabilities without granting SSH access to the server.
Step 3: Basic SFTP setup non-chroot
This keeps SSH access intact but enables a dedicated directory for SFTP users.
- Edit the SSH daemon config: sudo nano /etc/ssh/sshd_config
- Ensure the following lines exist adjust as needed:
Subsystem sftp /usr/lib/openssh/sftp-server - Add a dedicated group for SFTP users optional but helpful: sudo groupadd sftpusers
- Create a new user with no shell access to prevent SSH login, but allow SFTP only:
sudo useradd -m -s /usr/sbin/nologin -g sftpusers -d /home/sftp_user sftp_user
sudo mkdir -p /home/sftp_user/uploads
sudo chown root:root /home/sftp_user
sudo chmod 755 /home/sftp_user
sudo chown sftp_user:sftpusers /home/sftp_user/uploads - Apply permissions and set a strong password or use SSH keys for authentication
- Restart SSH to apply changes: sudo systemctl restart ssh
Note: This approach still allows SSH if the user has a login shell; using -s /usr/sbin/nologin blocks interactive shell but you can adjust as needed.
Step 4: Chrooted SFTP sftp-only for isolation
This locks users into their home directory or a subset and prevents SSH access.
- Create a dedicated group: sudo groupadd sftp
- Create an SFTP user with restricted shell: sudo useradd -m -d /home/sftpuser -s /usr/sbin/nologin -g sftp sftpuser
- Create the internal directory structure:
sudo mkdir -p /home/sftpuser/uploads
sudo chown root:root /home/sftpuser
sudo chmod 755 /home/sftpuser
sudo chown sftpuser:sftp /home/sftpuser/uploads - Configure SSH for chroot:
sudo nano /etc/ssh/sshd_config
Add at the end:
Match Group sftp
ChrootDirectory %h
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp - Restart SSH: sudo systemctl restart ssh
- Test: from another machine, connect with: sftp sftpuser@your_server_ip
Note: If you want multiple users, add them to the sftp group and create their personal chroot directories within their home directories.
Step 5: User and permission management best practices
- Use Key-based SSH authentication for admin access; keep password login disabled if possible.
- Regularly review /etc/ssh/sshd_config for changes and keep backups.
- Limit SSH access to specific users with AllowUsers or AllowGroups:
- In sshd_config, add: AllowUsers youradmin or AllowGroups sshadmins
- Use a non-standard SSH port if feasible, and adjust firewall rules accordingly.
- Implement two-factor authentication 2FA for admin access where possible.
- Set up automatic expire or rotation for user accounts that are temporary.
Step 6: Firewall and security hardening
- Allow SSH from trusted IPs or via VPN
- Basic UFW setup:
sudo ufw allow 22/tcp
sudo ufw enable
sudo ufw status - If you change SSH port, adjust firewall rules accordingly:
sudo ufw allow 2222/tcp - Clear unused keys and disable root login:
sudo nano /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no after setting up keys
Step 7: SFTP-specific security tips
- Disable password authentication for SFTP users if keys are in use.
- Use fail2ban to block repeated failed login attempts:
sudo apt install -y fail2ban
Copy default config: sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Edit /etc/fail2ban/jail.local to enable SSH jail and configure bantime. - Regularly update the server: sudo apt update && sudo apt upgrade -y
- Monitor logs: tail -f /var/log/auth.log for authentication-related events
- For Windows clients, consider configuring an SFTP client with key-based authentication and a strong passphrase on private keys.
Step 8: Troubleshooting common issues
- Connection refused on port 22: Ensure sshd is running and firewall allows port 22
- SFTP directory permissions errors: Ensure the chroot directory is owned by root and not writable by others
- Permission denied publickey during login: Verify key permissions chmod 600 for private key and correct authorized_keys on the server
- SFTP not restricting to jail: Re-check Match block and ensure there are no conflicting SSHD directives
- SELinux or AppArmor blocking access: Check security module status and adjust profiles accordingly
Step 9: Practical examples and quick-start commands
- Quick SFTP test:
sftp user@serverthen use put/get
- Create a user with SFTP-only access chrooted, using a home directory as root for the jail:
sudo groupadd sftp
sudo useradd -m -d /home/sftpuser -s /usr/sbin/nologin -g sftp sftpuser
sudo mkdir -p /home/sftpuser/uploads
sudo chown root:root /home/sftpuser
sudo chmod 755 /home/sftpuser
sudo chown sftpuser:sftp /home/sftpuser/uploads
sudo nano /etc/ssh/sshd_configadd:
Match Group sftp
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
sudo systemctl restart ssh
- Delegate a specific directory to an SFTP user using a separate chroot:
sudo mkdir -p /home/sftpuser/exports
sudo chown root:root /home/sftpuser/exports
sudo chmod 755 /home/sftpuser/exports
sudo nano /etc/ssh/sshd_configadjust with a more granular Match block for the user
sudo systemctl restart ssh
Step 10: Performance and reliability considerations
- Use a dedicated storage volume for SFTP home directories if you’re handling large files or many users
- Consider logging SFTP activity to a separate log for auditing
- Plan backups for uploaded files and ensure restoration tests exist
Tables: Quick reference
| Setup Type | Pros | Cons |
|---|---|---|
| Basic SFTP non-chroot | Simple to implement; SSH still works; flexible | Not isolated; potential risk if users have SSH access |
| Chrooted SFTP SFTP-only | Strong isolation; safer for user file transfers | More complex to configure; must manage file permissions carefully |
Tips for production deployments
- Document every change in sshd_config and keep a rollback plan
- Use version control or configuration management tools Ansible, Puppet, Chef for reproducibility
- Schedule routine security reviews and penetration testing if possible
- Keep client software up to date, especially SFTP clients that rely on SSH libraries
FAQ Section
Frequently Asked Questions
What is SFTP and how is it different from FTP?
SFTP is the secure version of FTP, running over SSH to encrypt both traffic and authentication, unlike FTP which transfers data in plain text.
Can I have both SSH and SFTP users on the same server?
Yes, but it’s safer to isolate SFTP users especially via chroot and restrict SSH access to admin-only accounts.
How do I disable password authentication for SFTP users?
In /etc/ssh/sshd_config, set PasswordAuthentication no and ensure you have key-based authentication set up for those users.
What port does SFTP use?
SFTP typically uses SSH on port 22, but you can configure a different port for SSH if needed.
How do I create a dedicated SFTP group?
Sudo groupadd sftp
Then add users to that group and configure SSH to match that group for chroot or restricted access. How to Enable DNS on OpenVPN Server DD-WRT: A Step-by-Step Guide for DNS Over VPN and Router Setup 2026
How can I ensure SFTP users cannot access other parts of the filesystem?
Use chrooted SFTP with a Match Group block in sshd_config to isolate each user or group to their home directory.
How do I test an SFTP connection from Windows?
Use an SFTP client like WinSCP or FileZilla; connect with your username, server IP, and either password or an SSH key.
How can I audit SFTP activity?
Enable logging for SSH it logs SFTP actions under auth.log and consider rotating logs or sending to a SIEM solution.
What should I do if SFTP is not working after changes?
Check sshd_config for syntax errors you can test with sudo sshd -t, verify the SSH service is running, and review /var/log/auth.log for clues.
Is it safer to use a nonstandard SSH port?
Changing to a nonstandard port can reduce automated attacks, but you must adjust firewall rules and client configurations accordingly. How to enable line number in sql server step by step guide 2026
End of guide
If you want, I can tailor this setup to your environment—Ubuntu version, cloud provider, or a specific compliance standard.
Yes, you can enable an SFTP server on Ubuntu by installing and configuring OpenSSH server, setting up proper user permissions, and hardening the setup with chroot and key-based authentication. This guide walks you through a practical, step-by-step process—from a quick setup to a hardened, production-ready SFTP server. You’ll learn how to create SFTP-only users, use chroot jails, switch to a non-default port, and secure access with SSH keys. Plus, you’ll get troubleshooting tips, best practices, and handy commands you can reuse right away.
Useful URLs and Resources text only
- OpenSSH Official Documentation – openssh.com
- Ubuntu Server Guide – ubuntu.com
- SSH Best Practices – en.wikipedia.org/wiki/SSH
- SFTP vs FTP – differences explained – en.wikipedia.org/wiki/File_Transfer_Protocol
- UFW — Uncomplicated Firewall – ubuntu.com
What is SFTP and SSH?
SFTP stands for Secure File Transfer Protocol. It’s not a separate service by itself; it runs over SSH Secure Shell and uses the same authentication and encryption mechanisms as SSH. In practice, SFTP provides a secure way to transfer files between your machine and a remote server. Because it leverages SSH, you get strong encryption, integrity checks, and the ability to use public/private key authentication. That’s why many admins prefer SFTP over older FTP methods, which transmit credentials in plain text. How to Enable DNS Server in Packet Tracer: Setup, Configuration, and Troubleshooting 2026
Key takeaway: setting up SFTP on Ubuntu means configuring the SSH daemon sshd so file transfers happen securely, often with a restricted user experience like a jailed, non-privileged user.
Prerequisites
- A Ubuntu server 22.04 LTS or newer is common with sudo privileges.
- A user account you can elevate with sudo.
- Basic terminal familiarity no heavy Linux expertise required, just follow commands.
- Optional: a client machine to test from could be Windows with WSL or a macOS/Linux box.
Optional but recommended:
- A domain name or a static IP for easier access.
- A firewall setup UFW to control access.
- SSH keys prepared for passwordless login.
Quick setup: a standard SFTP server
This path gives you a straightforward SFTP server that allows a normal user to connect and transfer files not jailed to a specific directory yet.
- Install OpenSSH Server
- sudo apt update
- sudo apt install openssh-server
- Verify the SSH service is running
- sudo systemctl status ssh
You should see “active running” in the output.
- Basic firewall rule if you use UFW
- sudo ufw allow ssh
- sudo ufw enable if not already enabled
- Create a regular user optional
- sudo adduser sftpuser
- sudo usermod -aG sudo sftpuser if you want admin privileges, usually not recommended for SFTP-only users
- Test an SFTP connection
- sftp sftpuser@your-server-ip
- If prompted, accept the fingerprint, enter the password, and try uploading/downloading a file.
What you’ll notice here: this is a standard SSH/SFTP setup where the user can log in and access the user’s home directory and its subdirectories if permissions allow. It’s fine for quick sharing, but not ideal for strict security or multi-user separation.
Step-by-step: configure SFTP-only jail for a user
If you want to restrict a user to a specific directory a common production requirement, you’ll enable a chroot jail and force SFTP. How to enable auditing on windows server 2012: Setup, Policy, and Logging for Comprehensive Monitoring 2026
- Install OpenSSH if you haven’t already
- sudo apt update
- sudo apt install openssh-server
- Create an SFTP group optional but helpful for multiple users
- sudo groupadd sftp
- sudo usermod -aG sftp sftpuser
- Prepare the directory structure
Important: the ChrootDirectory must be owned by root and not writable by others. Create a writable subdirectory inside the jail for the user’s files.
- sudo mkdir -p /home/sftpuser/files
- sudo chown root:root /home/sftpuser
- sudo chmod 755 /home/sftpuser
- sudo chown sftpuser:sftp /home/sftpuser/files
- Edit sshd_config to enable the SFTP jail
- sudo nano /etc/ssh/sshd_config
Add or modify the following lines you can place them near the end:
Subsystem sftp /usr/lib/openssh/sftp-server
Match Group sftp
ChrootDirectory %h
ForceCommand internal-sftp
X11Forwarding no
AllowTcpForwarding no
- Restart SSH service
- sudo systemctl restart ssh
- Test the jailed user
- sftp sftpuser@your-server-ip
- You should land in /files and be unable to navigate above the chroot.
Notes and tips:
- The ChrootDirectory must be owned by root and not writable by any other user. That’s why the user’s personal files live in a subdirectory inside the chroot i.e., /home/sftpuser/files.
- If you need multiple SFTP users in the jail, you can reuse the same pattern for a shared subdirectory or set up individual subdirectories.
- Make it scalable
- To add more users to the same jail, repeat steps 3 and 4 for each user, ensuring their home directories conform to the root-owned policy and the per-user writable subdirectories exist e.g., /home/sftpuser/files.
Advanced tip: If you want to jail a specific user but grant them the ability to upload to a shared directory, you can create a dedicated directory outside the jail and bind-mount it inside the jail, but that requires careful permission planning. How to Easily Get a CSR Code from Windows Server: Generate CSR via IIS Manager, PowerShell, CertReq 2026
Advanced: Non-default port and firewall considerations
Running SSH/SFTP on the default port 22 is convenient, but many admins move to a non-default port to reduce automated attacks. Here’s a safe way to do that.
- Choose a new port e.g., 2222
- Make a note: pick a port above 1024 that isn’t in use.
- Edit sshd_config
- sudo nano /etc/ssh/sshd_config
- Change or add: Port 2222
- Update firewall rules
- sudo ufw allow 2222/tcp
- If you previously allowed 22, you can keep it open for admin access or disable it later.
- Restart SSH
- sudo systemctl restart ssh
- Test the new port
- ssh -p 2222 sftpuser@your-server-ip
- sftp -P 2222 sftpuser@your-server-ip
Security note: If you move to a non-default port, you should also ensure your SSH configuration requires strong authentication see SSH keys below and that your firewall restricts other ports to legitimate services.
SSH keys, passwordless login, and authentication methods
Using SSH keys is a big win for security and convenience. Here’s a quick setup for passwordless login, which also improves protection against password-guessing attacks.
- Generate an SSH key pair on your client machine
- ssh-keygen -t ed25519 -C “[email protected]“
- Copy the public key to the server
- You can use ssh-copy-id if available: ssh-copy-id -i ~/.ssh/id_ed25519.pub sftpuser@your-server-ip -p 2222
- Or manually append the public key to ~/.ssh/authorized_keys on the server create the directory and file if needed, with proper permissions.
- Permit key-based authentication in sshd_config
- sudo nano /etc/ssh/sshd_config
- Ensure:
- PasswordAuthentication no
- ChallengeResponseAuthentication no
- PubkeyAuthentication yes
- If you changed Port, use the right port in the file or rely on the earlier port change.
- Restart SSH
- sudo systemctl restart ssh
- Test
- sftp -i ~/.ssh/id_ed25519 sftpuser@your-server-ip -P 2222
Tips:
- Keep a backup admin key in a separate, secure location.
- Consider two-factor authentication for SSH using a hardware key or one-time codes if your environment supports it.
Security best practices
- Limit root access: Do not set a real root login for SSH; use a standard user with sudo.
- Use key-based authentication, not password-based where possible.
- Disable password-based login for SFTP users if you can.
- Use ChrootDirectory for SFTP users to reduce risk from compromised credentials.
- Keep the system updated: sudo apt update && sudo apt upgrade regularly.
- Log and monitor SSH activity: check /var/log/auth.log or use a centralized logging solution.
- Regularly review user permissions and remove unused accounts.
Table: SFTP setup options How to Easily Switch Discord Server Ownership A Step By Step Guide 2026
| Option | Description | When to use |
|---|---|---|
| Standard SFTP no jail | Users access their home directories via SFTP | Simple file sharing, low risk in small setups |
| SFTP with ChrootDirectory | Jail users to a restricted directory | Multi-user deployments, higher security |
| Non-default SSH port | SSH runs on a port other than 22 | Reduce automated brute-force attempts |
| SSH keys only | Disable password login | Strong security, automation-friendly environments |
Testing and verification
- From a client, test the connection:
- sftp sftpuser@your-server-ip
- Or with a non-default port: sftp -P 2222 sftpuser@your-server-ip
- Check the server logs if something goes wrong:
- sudo tail -f /var/log/auth.log
- Validate file transfers by uploading a small file and downloading it back.
- Confirm the chroot works as intended by navigating or not navigating beyond the designated directory.
Troubleshooting common issues
- SSHD fails to restart after changes:
- Run sudo systemctl status ssh and sudo journalctl -xe to see the error messages.
- Permission denied for SFTP user inside a jail:
- Ensure the ChrootDirectory is owned by root and not writable by others.
- Ensure the user has a writable subdirectory inside the jail for internal file storage.
- Connection timed out on firewall:
- Confirm the port is open in the firewall and that the server is listening on that port: sudo ss -tuln | grep 22 or 2222
- SSH key authentication not working:
- Check permissions: ~/.ssh should be 700 and authorized_keys 600.
- Ensure the correct path to the private key is used on the client.
- Confirm PubkeyAuthentication is enabled in sshd_config.
Real-world tips and scenarios
- Small business file sharing: A single jailed user per client with per-client directories helps isolate access and keeps logs tidy.
- Dev/test environments: Move to a non-default port and use ephemeral SSH keys for automation tasks, then rotate keys regularly.
- Remote teams with Windows clients: Windows users can use vendors like WinSCP or FileZilla to SFTP with your SSH server.
Performance considerations
- SFTP performance is generally good on modern hardware. For large file transfers, consider enabling SSH compression if network bandwidth is the bottleneck and CPU isn’t taxed in sshd_config: Compression yes.
- If you expect many concurrent transfers, monitor system load and tune the number of allowed connections in your SSH configuration if needed UseMaxStartups, UsePAM, etc., but apply carefully.
Troubleshooting quick references
- Check status: systemctl status ssh
- Check syntax: sudo sshd -t
- Restart after changes: sudo systemctl restart ssh
- Test connectivity: ssh -p 2222 sftpuser@server_ip and sftp -P 2222 sftpuser@server_ip
- Firewall: sudo ufw status; sudo ufw allow 2222/tcp
Frequently Asked Questions
What is the difference between SFTP and FTPS?
SFTP runs over SSH and is encrypted by default, while FTPS FTP over SSL is a secure extension of FTP using TLS. SFTP is generally simpler to configure with SSH keys and chroot, while FTPS requires certificate management and can be more firewall-unfriendly.
How do I install OpenSSH on Ubuntu?
- sudo apt update
- sudo apt install openssh-server
- sudo systemctl enable –now ssh
How can I restrict SFTP users to a specific directory?
Use a chroot jail in sshd_config, typically with ChrootDirectory and ForceCommand internal-sftp, and ensure the jail directory is owned by root.
How do I create an SFTP-only user group?
Create a group e.g., sudo group isn’t needed for SFTP-only. Then add users to that group and configure sshd_config with a Match Group sftp block to apply jail and constraints.
How do I use SSH keys for authentication?
Generate an SSH key pair on the client, copy the public key to the server’s ~/.ssh/authorized_keys, and disable password authentication in sshd_config for stronger security.
Can I run SFTP on a non-default port?
Yes. Change Port in sshd_config and adjust firewall rules accordingly e.g., ufw allow 2222/tcp. Remember to restart ssh after changes. How to Easily Find Your DNS Server Settings: Quick Guide to DNS, Resolvers, and Network Configuration 2026
How do I test SFTP access from Windows?
Windows users can use clients like WinSCP or FileZilla to connect via SFTP using the server’s address and port, with either password or a private key.
How can I monitor SFTP activity?
Check /var/log/auth.log for login events and file transfer activity. Consider enabling advanced logging or a centralized log manager for larger deployments.
Is it safe to disable password authentication?
For servers accessed publicly, yes—passwordless login via SSH keys is safer. If you disable passwords, you should ensure you have at least one valid key-based login before removing password authentication.
What should I do if my SFTP connection intermittently fails?
Check the SSH server logs, verify network reachability, ensure the port is open on firewalls, and confirm there are no overnight changes to sshd_config like a mismatched Port setting.
Can I share a single SFTP directory with multiple users?
Yes. Create a common writable subdirectory inside each user’s jailed home or a shared subdirectory under a shared chroot, and carefully configure permissions to prevent cross-user access where needed. How to drop tde certificate in sql server a step by step guide: remove tde certificate safely in sql server, step by step 2026
What are best practices for backups with an SFTP server?
Back up the server’s sshd_config, authorized_keys, and the file storage directory. Use versioned backups, verify restore procedures, and test access after restoration.
How do I upgrade OpenSSH safely?
- sudo apt update
- sudo apt upgrade openssh-server
- sudo systemctl restart ssh
- Validate with a test connection to ensure no disruption to existing users
This guide gives you a solid, production-ready approach to enabling and securing an SFTP server on Ubuntu. By using chroot jails, SSH keys, and thoughtful port/firewall choices, you can provide reliable, secure file transfer for users and teams while keeping admin overhead manageable. If you’re deploying at scale, consider adding centralized monitoring, structured access control, and regular key management to stay ahead of security concerns.
Sources:
Comment installer un vpn sur une smart tv samsung en 2025 le guide complet
梯子 意思是什么?全面解析vpn:你的网络自由通行证——翻墙、隐私保护与地理限制绕行指南
Vpn网址使用与选择指南:全面解析VPN网址在中国与全球的访问、隐私与速度优化 How to Easily Exit X Server on Ubuntu 2026