0
0
Fork 0
mirror of https://github.com/atmoz/sftp.git synced 2025-01-26 13:50:57 -05:00
atmoz-sftp/entrypoint

45 lines
1 KiB
Text
Raw Normal View History

2014-10-07 21:34:24 +02:00
#!/bin/bash
2014-10-21 03:21:53 +02:00
for users in "$@"; do
IFS=':' read -a data <<< "$users"
2014-10-07 21:34:24 +02:00
user="${data[0]}"
pass="${data[1]}"
if [ "${data[2]}" == "e" ]; then
2015-01-03 13:10:38 +01:00
chpasswdOptions="-e"
uid="${data[3]}"
gid="${data[4]}"
else
uid="${data[2]}"
gid="${data[3]}"
fi
2015-01-03 13:10:38 +01:00
useraddOptions="--create-home --no-user-group"
if [ -n "$uid" ]; then
2015-01-03 13:10:38 +01:00
useraddOptions="$useraddOptions --non-unique --uid $uid"
fi
if [ -n "$gid" ]; then
2015-01-03 13:10:38 +01:00
useraddOptions="$useraddOptions --gid $gid"
2014-12-31 16:42:09 +01:00
groupadd --gid $gid $gid
fi
2015-01-03 13:10:38 +01:00
useradd $useraddOptions $user
2014-10-07 21:34:24 +02:00
chown root:root /home/$user
chmod 755 /home/$user
2014-10-21 03:21:53 +02:00
if [ -z "$pass" ]; then
pass="$(echo `</dev/urandom tr -dc A-Za-z0-9 | head -c256`)"
2015-01-03 13:10:38 +01:00
chpasswdOptions=""
2014-10-21 03:21:53 +02:00
fi
2015-01-03 13:10:38 +01:00
echo "$user:$pass" | chpasswd $chpasswdOptions
cat /home/$user/.ssh/keys/* >> /home/$user/.ssh/authorized_keys
chown $user /home/$user/.ssh/authorized_keys
chmod 600 /home/$user/.ssh/authorized_keys
2014-10-07 21:34:24 +02:00
done
2014-10-21 03:21:53 +02:00
exec /usr/sbin/sshd -D