Skip to content

Commit

Permalink
create sftp user
Browse files Browse the repository at this point in the history
  • Loading branch information
pothi committed Feb 14, 2017
1 parent fb79503 commit a0a1a39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
2 changes: 2 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ source /root/wp-in-a-box/scripts/install-base.sh
source /root/wp-in-a-box/scripts/install-firewall.sh
source /root/wp-in-a-box/scripts/install-nginx.sh
source /root/wp-in-a-box/scripts/install-mysql.sh
source /root/wp-in-a-box/scripts/create-sftp-user.sh
source /root/wp-in-a-box/scripts/install-mysql.sh

# take a backup
echo 'Taking an initial backup'
Expand Down
37 changes: 20 additions & 17 deletions scripts/create-sftp-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ SSHD_CONFIG='/etc/ssh/sshd_config'

if [ ! -d "/home/${BASE_NAME}" ]; then
groupadd --gid=1010 $WP_SFTP_USER &> /dev/null
useradd --uid=1010 --gid=1010 --shell=/usr/bin/zsh -m --home-dir /home/${BASE_NAME}/ $WP_SFTP_USER &> /dev/null
useradd --uid=1010 --gid=1010 -m --home-dir /home/${BASE_NAME}/ $WP_SFTP_USER &> /dev/null
# use the following, if the user prefers ZSH shell
# useradd --uid=1010 --gid=1010 --shell=/usr/bin/zsh -m --home-dir /home/${BASE_NAME}/ $WP_SFTP_USER &> /dev/null

groupadd ${BASE_NAME} &> /dev/null
else
echo "the default directory /home/${BASE_NAME} already exists!"; exit 1
fi

# "web" is meant for SFTP only user/s
gpasswd -a $WP_SFTP_USER ${BASE_NAME} &> /dev/null
# "web" is meant for SFTP only user/s
gpasswd -a $WP_SFTP_USER ${BASE_NAME} &> /dev/null

mkdir -p /home/${BASE_NAME}/{.aws,.composer,.ssh,.well-known,Backup,bin,git,log,others,php/session,scripts,sites,src,tmp,mbox,.npm,.wp-cli} &> /dev/null
mkdir -p /home/${BASE_NAME}/Backup/{files,databases}
mkdir -p /home/${BASE_NAME}/{.aws,.composer,.ssh,.well-known,Backup,bin,git,log,others,php/session,scripts,sites,src,tmp,mbox,.npm,.wp-cli} &> /dev/null
mkdir -p /home/${BASE_NAME}/Backup/{files,databases}

chown -R $WP_SFTP_USER:$WP_SFTP_USER /home/${BASE_NAME}
chown root:root /home/${BASE_NAME}
chmod 755 /home/${BASE_NAME}
chown -R $WP_SFTP_USER:$WP_SFTP_USER /home/${BASE_NAME}
chown root:root /home/${BASE_NAME}
chmod 755 /home/${BASE_NAME}

#-- allow the user to login to the server --#
# older way of doing things by appending it to AllowUsers directive
Expand Down Expand Up @@ -103,11 +102,15 @@ fi # /Match group ${BASE_NAME}

WP_SFTP_PASS=$(pwgen -s 18 1)

echo "$WP_SFTP_USER:$WP_SFTP_PASS" | chpasswd
echo "$WP_SFTP_USER:$WP_SFTP_PASS" | chpasswd

echo; echo "SFTP username is $WP_SFTP_USER"; echo;
echo; echo "SFTP password is $WP_SFTP_PASS"; echo;
echo 'Please make a note of these somewhere safe'
echo 'Also please test if things are okay!'
echo; echo "SFTP username is $WP_SFTP_USER"; echo;
echo; echo "SFTP password is $WP_SFTP_PASS"; echo;
echo 'Please make a note of these somewhere safe'
echo 'Also please test if things are okay!'

# Next Step - Setup PHP-FPM pool
# Next Step - Setup PHP-FPM pool
else
echo "the default directory /home/${BASE_NAME} already exists!"
# exit 1
fi # end of if ! -d "/home/${BASE_NAME}" - whoops

0 comments on commit a0a1a39

Please sign in to comment.