summaryrefslogtreecommitdiffstats
path: root/mgacreatehome
blob: 3c0fc140029ae214ab972c551332cfa1e24a3594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh

# script to create home directory with ssh key
# takes two arguments :
# - login
# - URL for ssh key

test $# -eq 2 || exit 1
login="$1"
sshkeyurl="$2"
sshkeyfile=`mktemp`
homeroot='/home'

id "$login" || exit 2
wget -O "$sshkeyfile" "$sshkeyurl" || exit 2
cat "$sshkeyfile"
echo "Press enter to validate"
read z

test ! -d "$homeroot/$login" && cp -a /etc/skel "$homeroot/$login"
mkdir "$homeroot/$login/.ssh"
cat "$sshkeyfile" >> "$homeroot/$login/.ssh/authorized_keys"
rm -f "$sshkeyfile"
chmod 700 "$homeroot/$login/.ssh"
chmod 600 "$homeroot/$login/.ssh/authorized_keys"
chown -R "$login":mga-users "$homeroot/$login"