2014-10-07 15:34:24 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-10-20 13:43:07 -04:00
|
|
|
# Add users (user:pass[:e][:[uid][:gid]][,...])
|
2014-10-07 15:34:24 -04:00
|
|
|
IFS=',' read -a users <<< "$SFTP_USERS"
|
|
|
|
for userData in "${users[@]}"; do
|
|
|
|
IFS=':' read -a data <<< "$userData"
|
|
|
|
user="${data[0]}"
|
|
|
|
pass="${data[1]}"
|
|
|
|
|
2014-10-20 13:43:07 -04:00
|
|
|
if [ "${data[2]}" == "e" ]; then
|
|
|
|
chpasswdParams="-e"
|
|
|
|
uid="${data[3]}"
|
|
|
|
gid="${data[4]}"
|
|
|
|
else
|
|
|
|
uid="${data[2]}"
|
|
|
|
gid="${data[3]}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
useraddParams="-m -N"
|
|
|
|
|
|
|
|
if [ -n "$uid" ]; then
|
|
|
|
useraddParams="$useraddParams -o -u $uid"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$gid" ]; then
|
|
|
|
useraddParams="$useraddParams -g $gid"
|
|
|
|
fi
|
|
|
|
|
|
|
|
useradd $useraddParams "$user"
|
|
|
|
echo "$user:$pass" | chpasswd $chpasswdParams
|
2014-10-07 15:34:24 -04:00
|
|
|
chown root:root /home/$user
|
|
|
|
chmod 755 /home/$user
|
|
|
|
done
|
|
|
|
|
|
|
|
# Run SSH
|
|
|
|
/usr/sbin/sshd -D
|