0
0
Fork 0
mirror of https://github.com/atmoz/sftp.git synced 2024-11-17 12:51:33 -05:00
atmoz-sftp/run

56 lines
1.2 KiB
Text
Raw Normal View History

2014-10-07 15:34:24 -04:00
#!/bin/bash
2014-10-20 21:21:53 -04:00
for users in "$@"; do
# user:pass[:e][:[uid][:gid]]
IFS=':' read -a data <<< "$users"
2014-10-07 15:34:24 -04:00
user="${data[0]}"
pass="${data[1]}"
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"
2014-10-07 15:34:24 -04:00
chown root:root /home/$user
chmod 755 /home/$user
2014-10-20 21:21:53 -04:00
if [ -z "$pass" ]; then
# just make a very long and random password
pass="$(echo `</dev/urandom tr -dc A-Za-z0-9 | head -c256`)"
fi
echo "$user:$pass" | chpasswd $chpasswdParams
# if [ -f /home/$user/.ssh/authorized_keys ]; then
# chown -R $user:users /home/$user/.ssh
# chmod 400 /home/$user/.ssh/authorized_keys
# fi
done
cd /public_keys
for user in *; do
if id -u $user >/dev/null 2>&1; then
mkdir -p /home/$user/.ssh
cp $user /home/$user/.ssh/authorized_keys
chown $user:users /home/$user/.ssh/authorized_keys
fi
2014-10-07 15:34:24 -04:00
done
2014-10-20 21:21:53 -04:00
cd /root
2014-10-07 15:34:24 -04:00
2014-10-20 21:21:53 -04:00
exec /usr/sbin/sshd -D