0
0
Fork 0
mirror of https://github.com/atmoz/sftp.git synced 2024-11-17 12:51:33 -05:00
atmoz-sftp/run
Adrian Dvergsdal 461e64c547 Update syntax
2014-10-28 18:58:03 +01:00

40 lines
834 B
Bash

#!/bin/bash
for users in "$@"; do
# user:[pass[:e]][:[uid][:gid]]
IFS=':' read -a data <<< "$users"
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"
chown root:root /home/$user
chmod 755 /home/$user
if [ -z "$pass" ]; then
pass="$(echo `</dev/urandom tr -dc A-Za-z0-9 | head -c256`)"
chpasswdParams=""
fi
echo "$user:$pass" | chpasswd $chpasswdParams
done
exec /usr/sbin/sshd -D