Skip to content

Instantly share code, notes, and snippets.

@oscarcck
Created July 25, 2014 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarcck/f6ef52aecc649551f381 to your computer and use it in GitHub Desktop.
Save oscarcck/f6ef52aecc649551f381 to your computer and use it in GitHub Desktop.
SFTP Only access using OPenSSH with ChrootDirectory

Restricted SFTP-only access to a single directory using OpenSSH

Edit /etc/ssh/sshd_config Match Group sftp-users

Force the connection to use SFTP and chroot to the required directory.

ForceCommand internal-sftp ChrootDirectory /home/sftp-users

Disable tunneling, authentication agent, TCP and X11 forwarding.

PermitTunnel no AllowAgentForwarding no AllowTcpForwarding no X11Forwarding no

sudo addgroup sftp-users sudo adduser --ingroup sftp-users testsftp

sudo chown root /home/sftp-users sudo chmod go-w /home/sftp-users sudo mkdir /home/sftp-users/public sudo chgrp sftp-users /home/sftp-users/public sudo chmod g+rwx /home/sftp-users/public

sudo service ssh restart

ref: http://passingcuriosity.com/2014/openssh-restrict-to-sftp-chroot/ http://askubuntu.com/questions/49271/how-to-setup-a-sftp-server-with-users-chrooted-in-their-home-directories http://askubuntu.com/questions/134425/how-can-i-chroot-sftp-only-ssh-users-into-their-homes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment