July 18, 2022

Set Up SFTP Chroot Jail

First we need to create separate group for the users who will be able to use only sftp service.

# sudo groupadd sftpgroup


After that we can create as much users as we need by using the command:

# sudo useradd -g sftponly -s /bin/false -m -d /home/username username

# sudo passwd username

# sudo usermod -G sftpgroup -s /bin/false username
# sudo chown root: /home/sftpgroup
# sudo chmod 755 /home/sftpgroup


# sudo vim /etc/ssh/sshd_config
Match group sftpgroup
ForceCommand internal-sftp
PasswordAuthentication yes
ChrootDirectory %h
PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding noX11Dorwarding no

ForceCommand internal-sftp

# ssudo systemctl restart ssh