-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathremote_user_creation
36 lines (28 loc) · 974 Bytes
/
remote_user_creation
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
34
35
36
#!/bin//bash
hostfile=`cat /tmp/hosts`
read -p 'Username: ' usr
read -p 'Comment: ' cmnt
read -p 'User ID: ' uid
read -p 'Group: ' grp
cat > /tmp/file.txt << END
#!/bin/bash
sudo useradd $usr -c "$cmnt" -u $uid -g $grp
sudo mkdir /home/$usr/.ssh
sudo chown $usr:$grp /home/$usr/.ssh
sudo chmod 700 /home/$usr/.ssh
sudo touch /home/$usr/.ssh/authorized_keys
sudo cp /tmp/id_rsa.pub /home/$usr/.ssh/authorized_keys
sudo chmod 600 /home/$usr/.ssh/authorized_keys
sudo chown $usr:$grp /home/$usr/.ssh/authorized_keys
sudo rm -fr /tmp/id_rsa.pub
END
for i in $hostfile; do
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 $i "ls" &> /dev/null
if [[ $? -eq 0 ]];then
echo "success in $i"
scp /tmp/id_rsa.pub $i:/tmp
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 $i < /tmp/file.txt
else
echo "error in $i"
fi
done