-
Notifications
You must be signed in to change notification settings - Fork 0
/
useradd.sh
46 lines (34 loc) · 1.12 KB
/
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
44
45
46
#!/bin/bash
read -r -e -p "Set new username: " username
user=${username,,} # tolower
useradd $user
passwd $user
read -r -p "Add user to sudoers? [y/N] " response
res=${response,,} # tolower
if [[ $res =~ ^(yes|y)$ ]]; then
#gpasswd -a $user wheel # si wheel no esta autorizado en sudoers esto no funciona
echo >> /etc/sudoers
echo "# User $user authorization:" >> /etc/sudoers
echo "$user ALL=(ALL) ALL" >> /etc/sudoers
fi
# SSH: RSA key
mkdir -p /home/$user/.ssh
for f in pub_keys/*.pub; do (cat $f; echo '') >> /home/$user/.ssh/authorized_keys; done
chown -R $user:$user /home/$user/.ssh
chown $user:$user /home/$user
chmod 700 /home/$user/.ssh
chmod 600 /home/$user/.ssh/authorized_keys
# Change Shell to Bash:
chsh -s /bin/bash $user
# Add bash aliases config in .bashrc (only if it does not exist yet):
cp .bash_aliases /home/$user/
grep .bash_aliases /home/$user/.bashrc || cat >> /home/$user/.bashrc <<EOF
# User specific aliases and functions
if [ -f /home/$user/.bash_aliases ]; then
. /home/$user/.bash_aliases
fi
EOF
# NANO, colorines:
for f in /usr/share/nano/*.nanorc; do
echo "include $f" >> /home/$user/.nanorc
done