SFTP (SSH File Transfer Protocol) runs over SSH and encrypts credentials and data in transit, unlike plain FTP, which sends everything in clear text. This guide walks you through setting up an SFTP-only server on Arch Linux with chroot: users in the sftpusers group get only internal-sftp (no shell) and are restricted to /srv/sftp.
In this guide you’ll:
- Install and enable OpenSSH (
sshd) on Arch Linux withpacman - Create a shared chroot under
/srv/sftp, add thesftpusersgroup, and create SFTP-only users with/sbin/nologin - Configure
/etc/ssh/sshd_configwithMatch Group sftpusers,ChrootDirectory /srv/sftp, andForceCommand internal-sftp - Test access with the
sftpclient and optionally add extra directories under/srv/sftp
Related SFTP guides:
- How to set up an SFTP server on Debian 11
- How to work with SFTP client in Linux (10 SFTP commands)
- How to set up an SFTP server on OpenSUSE Leap 15.3
- How to install and set up SFTP server in Ubuntu 20.04
- How to set up an SFTP server on CentOS 8 / RHEL 8
- Download files from SFTP server using Python
- List, upload and download files from an SFTP server using Go
Prerequisites
To follow along this guide ensure you have the following:
- Arch Linux machine
- Root access to the server or a user with root access
- Internet access from the server
Ensuring that the server is up to date
Before proceeding, ensure your system is up to date. Use this command to refresh the system packages and update them.
| |
2. Ensuring that the SSH service is installed
Verify that the ssh is installed:
| |
If ssh is not installed, install with this command:
| |
Now that it is installed, start the service
| |
Confirm its status
| |
Creating users and groups and adding the necessary directories
Next we will ensure that the necessary users are present in the system. In my case, I would like to have the sftp users home as /srv/sftp
Let us create the home /srv/sftp with this command:
| |
Then let us create an umbrella group for SFTP only
| |
Then create an sftp only user called citizix:
| |
The above options do the following:
-G sftpusers: Create user, append tosftpusersgroup-d /srv/sftp/citizix: Set home dir as/srv/sftp/citizix-s /sbin/nologin: We do not want the user to login, so no ssh login shell- Finally, username as
citizix
Then add password to the created user using this command:
| |
Configuring the ssh service
Now that we have installed the necessary software and created the users and groups, let us configure ssh.
Ensure password authentication is enabled for ssh. Edit the config file here /etc/ssh/sshd_config:
| |
Then ensure this line is not commented:
| |
Next, we need to add rules for the users in the sftpusers group to be considered as sftp. Edit the config file:
| |
Add this content at the bottom of the file:
| |
Then restart sshd to reload the config:
| |
Verify that sshd is running as expected:
| |
Verifying that the set up is working as expected
After creating the user and adding the SFTP configuration, let’s test the setup with:
| |
Now we have sftp server up and running with a user configured!
The users will be able to login to the server and access files and directories located in their home directory. If you want to give the user to other directories outside their own directory, just make sure the user has enough rights to access. These directories and files have to be within the sftp directory - /srv/sftp.
Example: to give the user access to a directory such as /srv/sftp/paymentfiles:
Create the directory
| |
Then assign the user(citizix) access by making them own the directory:
| |
Users can then access that directory when they connect via SFTP.
Frequently Asked Questions (FAQ)
What is SFTP?
SFTP (SSH File Transfer Protocol) is a secure file transfer protocol that runs over SSH. Unlike FTP, it encrypts both authentication and data. OpenSSH provides the SFTP subsystem (internal-sftp), so no separate FTP server is needed on Arch Linux.
What port does SFTP use on Arch Linux?
SFTP uses the same port as SSH: port 22. The sshd service (OpenSSH daemon) handles both SSH logins and SFTP. Ensure sshd is enabled and listening: sudo systemctl enable --now sshd.
How do I restrict users to SFTP only (no shell) on Arch?
Create users with shell /sbin/nologin and add them to a group (e.g. sftpusers). In /etc/ssh/sshd_config, add a Match Group sftpusers block with ChrootDirectory /srv/sftp and ForceCommand internal-sftp. Restart sshd. Users in that group will only get an SFTP session, not a login shell.
Why use ChrootDirectory for SFTP?
ChrootDirectory restricts SFTP users to a specific directory (e.g. /srv/sftp) so they cannot browse the rest of the filesystem. On Arch we use a shared chroot (/srv/sftp); each user’s home can be a subdirectory (e.g. /srv/sftp/citizix). The chroot directory and its parents must be owned by root and not writable by the user.
How do I enable SSH/SFTP on Arch Linux at boot?
Run sudo systemctl enable sshd so the OpenSSH daemon starts on boot. Use sudo systemctl start sshd to start it immediately. The service name on Arch is sshd (not ssh).
Conclusion
You now have an SFTP-only server on Arch Linux with chroot to /srv/sftp: users in the sftpusers group can only use SFTP (no shell) and are limited to that directory. For client usage, see how to work with the SFTP client in Linux, or automate transfers with Python or Go.