forked from OraOpenSource/OXAR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_user.sh
35 lines (23 loc) · 891 Bytes
/
create_user.sh
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
#!/bin/bash
#Create user with RSA public key (so no password)
#CU = Create User
OOS_UTIL_CU_USERNAME=$1
OOS_UTIL_CU_RSA_PUB_KEY_URL=$2
if [[ $(whoami) != "root" ]]; then
echo "This program must be run as root."
echo "Try using sudo"
exit 1
fi
#Create User
useradd $OOS_UTIL_CU_USERNAME
#Add User to sudoers
#echo '$OOS_UTIL_CU_USERNAME ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
#Add user to wheel group (CentOS)
useradd -G wheel $OOS_UTIL_CU_USERNAME
#Setup for authorized_keys
runuser -l $OOS_UTIL_CU_USERNAME -c 'mkdir -p ~/.ssh'
runuser -l $OOS_UTIL_CU_USERNAME -c 'chmod 700 ~/.ssh'
runuser -l $OOS_UTIL_CU_USERNAME -c 'touch ~/.ssh/authorized_keys'
runuser -l $OOS_UTIL_CU_USERNAME -c 'chmod 640 ~/.ssh/authorized_keys'
#Download ssh key and pipe into authorized_keys
curl -L "$OOS_UTIL_CU_RSA_PUB_KEY_URL" >> $(eval echo "~$OOS_UTIL_CU_USERNAME")/.ssh/authorized_keys