Skip to content

Instantly share code, notes, and snippets.

@alexclifford
Last active May 25, 2018 15:26
Show Gist options
  • Save alexclifford/8447110 to your computer and use it in GitHub Desktop.
Save alexclifford/8447110 to your computer and use it in GitHub Desktop.
Quick script for adding a new SFTP user/directory to an existing SFTP setup on Ubuntu.
#!/bin/sh
######################################################
# Create a new SFTP user and configure their chroot
######################################################
if [ $# -ne 2 ]; then
echo "Usage: add_sftp_user.sh username password"
exit 0
fi
useradd -d /sftp -s /bin/false -G $(grep sftpusers /etc/group | cut -d: -f3) -p `mkpasswd -m SHA-512 $2` $1
mkdir -p /sftp/$1/sftp
chown root:sftpusers /sftp/$1
chown -R $1:sftpusers /sftp/$1/sftp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment