generated from github/codespaces-blank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
useradd.sh
43 lines (33 loc) · 929 Bytes
/
useradd.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
36
37
38
39
40
41
42
43
#!/bin/bash
#================#
# For CentOS 7.0 #
#================#
######## CONFIG ##########
user="user"
password="Password"
##########################
# Adding user
/usr/sbin/useradd "$user" -s "/usr/bin/bash" -m -d "/home/$user"
# Adding user & password
echo "$user:$password" | /usr/sbin/chpasswd
usermod -a -G wheel $user
mkdir /home/$user/web /home/$user/.ssh
# Add SSH Authorized KEY
cat << EOF >/home/$user/.ssh/authorized_keys
ssh-rsa AAAAB_RSA_KEYS_PUB
EOF
# Add user SSH Authorized KEY
cat << EOF >/etc/sudoers.d/Init-users
# User SSH Authorized KEY
$user ALL=(ALL) NOPASSWD: ALL
EOF
# Permissions
chown -R $user:$user /home/$user/ /home/$user/.ssh
chmod -R o+x /home/$user/
chmod -R 755 /home/$user
#gpasswd -a nginx $user
chmod -R 700 /home/$user/.ssh
chmod 600 /home/$user/.ssh/authorized_keys
# Add to SELinux dir
chcon -Rt httpd_sys_content_t /home/$user/web
setfacl -R -m u:nginx:rwx /home/$user/web