Debian 10 Buster
Sponsored Link

OpenSSH : SFTP only + Chroot2019/07/10

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

root@dlp:~#
groupadd sftp_users

# for example, apply to a user [debian] for SFTP only

root@dlp:~#
usermod -aG sftp_users debian

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

#
Subsystem sftp /usr/lib/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 ssh

[2] Try to access with a user to verify settings.
debian@www:~$
ssh debian@10.0.0.30

debian@10.0.0.30's password:
This service allows sftp connections only.
Connection to 10.0.0.30 closed.    
# denied normally
debian@www:~$
sftp debian@10.0.0.30

Connecting to 10.0.0.30...
debian@10.0.0.30's password:
sftp>
ls -l

drwxr-xr-x    2 1001     1001         4096 Jul 10 06:16 buster
drwxr-xr-x    3 1000     1000         4096 Jul 10 07:17 debian
sftp>
pwd

Remote working directory: /
sftp>
exit

Matched Content