Create a gist now

Instantly share code, notes, and snippets.

Shell Script for Setting Up SFTP Server with EasyEngine
#!/bin/bash
# WARNING: Only run this script once per server.
####
## Creating SFTP Users - Initial Setup for New Server
####
####
## Gist: https://gist.github.com/NichlasB/e938cddb7876fd74af09dc00ca537a2c
## Resource: https://easyengine.io/docs/chroot-sftp-easyengine/
## Resource: https://www.howtoforge.com/restricting-users-to-sftp-plus-setting-up-chrooted-ssh-sftp-debian-squeeze
## Resource: https://blog.rootshell.be/2009/03/01/keep-an-eye-on-ssh-forwarding/
## Resource: https://raymii.org/s/tutorials/Limit_access_to_openssh_features_with_the_Match_keyword.html
## Resource: https://unix.stackexchange.com/questions/286342/can-not-succeed-in-excluding-user-in-match-directive-in-sshd-config
####
# Create Hosting Users Group
addgroup hostingusers
# Setup SFTP Server (original line: <Subsystem sftp /usr/lib/openssh/sftp-server>)
sed -i "/^Subsystem sftp.*/c\Subsystem sftp internal-sftp" /etc/ssh/sshd_config
# Add Chroot SSHD Match Rules to /etc/ssh/sshd_config File
cat <<EOF >> /etc/ssh/sshd_config
Match Group hostingusers
X11Forwarding no
ChrootDirectory %h
AllowTcpForwarding no
ForceCommand internal-sftp
PasswordAuthentication yes
EOF
# Restart SSH Service
service ssh restart
@NichlasB
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment