Created
November 17, 2013 20:59
-
-
Save alexblackie/7518198 to your computer and use it in GitHub Desktop.
Add an SFTP-only user. Note: needs sshd_config to define the www-users group as sftp-only.
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/bash | |
#----------------------------------------------------------------------- | |
# Add User Script | |
#----------------------------------------------------------------------- | |
# Create directory | |
mkdir -p /var/www/$1 | |
# Add account | |
useradd -s/bin/sh -b/var/www -gwww-users $1 | |
# Set Password | |
passwd $1 | |
# Set public key | |
mkdir -p /var/www/$1/.ssh | |
chown $1 /var/www/$1/.ssh | |
chmod 700 /var/www/$1/.ssh | |
su -c "cd /var/www/$1/.ssh ; curl http://files.alexblackie.com/id_rsa.pub >> authorized_keys" $1 | |
# Set up webroots | |
mkdir /var/www/$1/public | |
mkdir /var/www/$1/private | |
chown $1:www-data /var/www/$1/public | |
chown $1 /var/www/$1/private | |
chmod 740 /var/www/$1/private |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment