Skip to content

Instantly share code, notes, and snippets.

@SeyedMostafaAhmadi
Last active March 11, 2022 15:44
Show Gist options
  • Save SeyedMostafaAhmadi/7faf82c552722e71232670be7a9cf23a to your computer and use it in GitHub Desktop.
Save SeyedMostafaAhmadi/7faf82c552722e71232670be7a9cf23a to your computer and use it in GitHub Desktop.
How to Restrict SFTP Users to Home Directories Using chroot Jail
# Create Group and User
groupadd your-groupname
adduser your-username --shell /sbin/nologin
# add your-username to your-groupname
usermod -aG your-groupname your-username
# Modify SSH Configuration File in /etc/ssh/sshd_config
Subsystem sftp internal-sftp
Match Group your-groupname
ChrootDirectory /specific-directory ### Owner This directory have be root
ForceCommand internal-sftp
X11Forwarding no
AllowTcpForwarding no
# Restart your ssh server
systemctl restart sshd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment