How to configure SFTP server on Linux?

Published on Aug. 22, 2023, 12:18 p.m.

To configure an SFTP server on Linux, you can follow these general steps:

  1. Install the SSH server software.
  2. Create the necessary groups and users for SFTP access.
  3. Configure the SSH server to allow SFTP access and configure the chroot directory for the SFTP users.
  4. Restart the SSH server to apply the changes.

The specific commands and configuration files you’ll need to modify depend on the Linux distribution you’re using. Here’s an example using Ubuntu:

  1. Install openssh-server:
sudo apt-get install openssh-server
  1. Create a new group and user that can be used to login with SFTP:
sudo groupadd sftpusers
sudo useradd -g sftpusers -d /incoming -s /bin/false sftpuser
  1. Edit the SSH configuration file at /etc/ssh/sshd_config to include the following lines:
Subsystem sftp internal-sftp
Match group sftpusers
ChrootDirectory /home/%u
ForceCommand internal-sftp
X11Forwarding no
AllowTcpForwarding no
  1. Restart the SSH server to apply the changes:
sudo service ssh restart

Now you should be able to use an SFTP client to connect to the server using the user “sftpuser” and the chroot directory will be set to /home/sftpuser.

Tags: