Fedora 34
Sponsored Link

OpenSSH : SFTP only + Chroot2021/04/29

 
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

# for example, set [fedora] user as SFTP only user

[root@dlp ~]#
usermod -aG sftp_users fedora

[root@dlp ~]#
vi /etc/ssh/sshd_config
# line 123 : comment out and add a line

#Subsystem      sftp    /usr/libexec/openssh/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 ~]#
systemctl restart sshd

[2] Verify working with a user set SFTP only setting.
[fedora@node01 ~]$
ssh dlp.srv.world

fedora@dlp.srv.world's password:
This service allows sftp connections only.
Connection to dlp.srv.world closed.  
# denied normally
[fedora@node01 ~]$
sftp dlp.srv.world

fedora@dlp.srv.world's password:
Connected to dlp.srv.world.
sftp> ls -l
drwx------    3 fedora   fedora         95 Apr 29 02:52 fedora
drwx------    3 1001     1001           95 Apr 29 01:59 redhat
sftp> pwd
Remote working directory: /
sftp> exit
Matched Content