Last active
April 2, 2019 07:44
-
-
Save serweb-labs/8f33d212522ca58ed715e06f5bf0fd69 to your computer and use it in GitHub Desktop.
add only sftp user to serverpilot app
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/bash | |
# $1 user | |
# $2 from path | |
# prerequisites: | |
# create sftp-only group | |
# sudo groupadd sftp-only | |
# add sftp-only configurations | |
# we need to modify the ssh configuration on file /etc/ssh/sshd_config replacing the following line: | |
# Subsystem sftp /usr/lib/openssh/sftp-server | |
# to: Subsystem sftp internal-sftp | |
# and add in end of file: | |
# Match group sftp-only | |
# PermitTunnel no | |
# X11Forwarding no | |
# AllowTcpForwarding no | |
# ForceCommand internal-sftp | |
if test "$#" -ne 2; then | |
echo "expected 2 params: {user} {from-path}" | |
exit 1 | |
fi | |
printf "add user $1\n" | |
read -n 1 -s -r -p "Press any key to continue" | |
printf "\n" | |
# create user | |
sudo adduser $1 | |
# prevent ssh access | |
sudo usermod -s /bin/false $1 | |
# add to server group | |
# (in serverpilot is "serverpilot") | |
sudo usermod -a -G serverpilot $1 | |
# add sft-only group | |
sudo usermod -a -G sftp-only $1 | |
# set de primary group | |
sudo usermod -g serverpilot $1 | |
printf "mounting the directory /home/$1/$(basename $2)\n" | |
read -n 1 -s -r -p "Press any key to continue" | |
printf "\n" | |
# create mountpoint container | |
sudo mkdir /home/$1/$(basename $2) | |
sudo chown $USER:serverpilot /home/$1/$(basename $2) | |
# mount the real path | |
sudo mount --bind $2 /home/$1/$(basename $2) | |
printf "add to crontab: mounting the directory /home/$1/$(basename $2)\n" | |
read -n 1 -s -r -p "Press any key to continue" | |
printf "\n" | |
#write out current crontab | |
crontab -l > /tmp/mycron | |
#echo new cron into cron file | |
echo "@reboot mount --bind $2 /home/$1/$(basename $2)" >> /tmp/mycron | |
#install new cron file | |
crontab /tmp/mycron | |
rm /tmp/mycron | |
printf "success\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment