Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added ability to add publickey
  • Loading branch information
farinspace committed Jul 25, 2015
1 parent ff8e4b3 commit e7ae659
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion add-sftp-user.sh
Expand Up @@ -2,7 +2,7 @@

###

echo -n "Username: (e.g. john-sftp)"
echo -n "Username: [e.g. john-sftp] "
read USERNAME

if [ -z "$USERNAME" ]
Expand All @@ -13,6 +13,27 @@ fi

###

echo -n "SSH Public Key, e.g. \"ssh-rsa [PUBLICKEY]\" (end input with ESC):"
read -d `echo -e "\e"` PUBLICKEY
echo ""

if [ -z "$PUBLICKEY" ]
then
echo "Public Key must not be empty"
exit
fi

###

groupadd -f sftp

useradd -g sftp -s /sbin/nologin -m $USERNAME

###

mkdir /home/$USERNAME/.ssh

touch /home/$USERNAME/.ssh/authorized_keys

# remove newlines from public key
echo "$PUBLICKEY" | sed ':a;N;$!ba;s/\n//g' >> /home/$USERNAME/.ssh/authorized_keys

0 comments on commit e7ae659

Please sign in to comment.