-
-
Save anonymous/514eb452a341ae646c81d174fea66783 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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