Ubuntu 24.04
Sponsored Link

OpenSSH : SFTP only + Chroot2024/04/26

 
Configure SFTP only + Chroot.
Some users who are applied this setting can access only with SFTP and also applied chroot directory.
[1] For example, Set [/home] as the Chroot directory.
# create a group for SFTP only

root@dlp:~#
groupadd sftp_users

# apply to a user [ubuntu] for SFTP only as an example

root@dlp:~#
usermod -aG sftp_users ubuntu

root@dlp:~#
vi /etc/ssh/sshd_config
# line 115 : comment out and add a line like below

#
Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp
# add to last line

Match Group sftp_users
    X11Forwarding no
    AllowTcpForwarding no
    ChrootDirectory /home
    ForceCommand internal-sftp

root@dlp:~#
systemctl restart ssh
[2] Try to access with a user and verify the settings.
ubuntu@node01:~$
ssh ubuntu@dlp.srv.world

Enter passphrase for key '/home/ubuntu/.ssh/id_ed25519':
This service allows sftp connections only.
Connection to dlp.srv.world closed.   # denied as settings

ubuntu@node01:~$
sftp ubuntu@dlp.srv.world

Enter passphrase for key '/home/ubuntu/.ssh/id_ed25519':
Connected to dlp.srv.world.
sftp>
Matched Content