FreeBSD 14
Sponsored Link

OpenSSH : SFTP only + Chroot2023/12/19

 
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:~ #
pw groupadd sftp_users

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

root@dlp:~ #
pw groupmod sftp_users -m freebsd

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

#
Subsystem sftp /usr/libexec/sftp-server
Subsystem sftp internal-sftp
# add to the end

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

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

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

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

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