Skip to content

Instantly share code, notes, and snippets.

/addsftpuser.sh Secret

Created June 19, 2016 19:49
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 anonymous/514eb452a341ae646c81d174fea66783 to your computer and use it in GitHub Desktop.
Save anonymous/514eb452a341ae646c81d174fea66783 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
G="sftpusers"
U=$1
P=$2
if [ -z "$1" ]
then
echo "no username given"
exit 1
fi
if [ -z "$2" ]
then
echo "no pubkey given"
exit 1
fi
echo "Adding $U to $G"
useradd -g $G -d /incoming -s /sbin/nologin $U
echo "Creating sftp dir"
mkdir -p /sftp/$U/incoming
chown $U:$G /sftp/$U/incoming
echo "setting pubkey access"
mkdir -p /home/$U/.ssh
echo "$P" > /home/$U/.ssh/authorized_keys
chmod 600 /home/$U/.ssh/authorized_keys
chmod 700 /home/$U/.ssh/
chown -R $U:$G /home/$U
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment