Last active
March 8, 2016 17:56
-
-
Save ohartl/f6aab7ae3bb0909b0ef3 to your computer and use it in GitHub Desktop.
create user that is restricted to sftp only, is jailed (chroot) and can still access certain directories outside his jail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# add group | |
groupadd sftp-fileshare | |
# add user | |
mkdir /home/sftp-fileshare-user1 | |
chown root:root /home/sftp-fileshare-user1 | |
chmod 0755 /home/sftp-fileshare-user1 | |
useradd --home /home/sftp-fileshare-user1 --shell /bin/false sftp-fileshare-user1 | |
usermod sftp-fileshare-user1 -g sftp-fileshare | |
passwd sftp-fileshare-user1 | |
# mount a directory outside jail | |
sudo mount --bind /var/www/somedir /home/sftp-fileshare-user1/somedir/ | |
# mount needs to be added to fstab, so its created again after restart | |
chown -R sftp-fileshare-user1:sftp-fileshare /home/sftp-fileshare-user1/somedir/ | |
# clear profiles etc, no need for them | |
cd /home/sftp-fileshare-user1 | |
rm .* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
/var/www/somedir /home/sftp-fileshare-user1/somedir/ none bind 0 0 | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
AllowUsers ... sftp-fileshare-user1 | |
Subsystem sftp internal-sftp | |
Match Group sftp-fileshare | |
ChrootDirectory %h | |
X11Forwarding no | |
AllowTcpForwarding no | |
ForceCommand internal-sftp | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment