-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mkuser
executable file
·33 lines (27 loc) · 1.08 KB
/
mkuser
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
28
29
30
31
32
33
#! /bin/bash
# Script de création de compte avec clé SSH github
read -p 'github username: ' U
useradd $U -m -s /usr/sbin/nologin
mkdir -p /home/$U/.ssh
curl -sL "https://github.com/$U.keys" > /home/$U/.ssh/authorized_keys
chown $U:$U -R /home/$U/.ssh
chmod 400 /home/$U/.ssh/authorized_keys
read -p 'which container ID (100..): ' CT
if [ "$CT" -lt "200" ]
then
lxc-attach -n $CT -- useradd $U -m -s /bin/bash
lxc-attach -n $CT -- mkdir -p /home/$U/.ssh
lxc-attach -n $CT -- wget -q "https://github.com/$U.keys"
lxc-attach -n $CT -- mv $U.keys /home/$U/.ssh/authorized_keys
lxc-attach -n $CT -- chown $U:$U -R /home/$U/.ssh
lxc-attach -n $CT -- chmod 400 /home/$U/.ssh/authorized_keys
lxc-attach -n $CT -- usermod -a -G sudo $U
else
ssh root@10.1.0.$CT useradd $U -m -s /bin/bash
ssh root@10.1.0.$CT mkdir -p /home/$U/.ssh
ssh root@10.1.0.$CT wget -q "https://github.com/$U.keys"
ssh root@10.1.0.$CT mv $U.keys /home/$U/.ssh/authorized_keys
ssh root@10.1.0.$CT chown $U:$U -R /home/$U/.ssh
ssh root@10.1.0.$CT chmod 400 /home/$U/.ssh/authorized_keys
ssh root@10.1.0.$CT usermod -a -G sudo $U
fi