-
Notifications
You must be signed in to change notification settings - Fork 9
/
add_user_ubunto.sh
52 lines (45 loc) · 1.58 KB
/
add_user_ubunto.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
47
48
49
50
51
52
#!/bin/bash
# Author name: Ruel Nopal
# Company: Ruel Nopal - IT Consultant.
# url: www.ruelnopal.com
# Creating users
# run this
# wget https://raw.githubusercontent.com/raketbizdev/code-snippits/master/add_user_ubunto.sh; sudo chmod 755 add_user_ubunto.sh; ./add_user_ubunto.sh;
# create username
echo 'Enter Desired Username:'
read username
sudo adduser ${username}
sudo usermod -aG sudo ${username}
sudo adduser ${username} www-data
sudo echo "${username} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
echo 'Add Firewall'
ufw app list
ufw allow OpenSSH
ufw enable
ufw status
cat /etc/passwd
grep '^${username}' /etc/passwd
echo 'restarting ssh'
sudo systemctl restart ssh
groups ${username}
sudo mkdir /home/${username}/.ssh
sudo touch /home/${username}/.ssh/authorized_keys
sudo chown -R ${username}:${username} /home/${username}/.ssh
echo 'Add public key to the authorized_keys:'
echo 'Enter public_key from your local machine:'
read pubkey
sudo cat >> /home/${username}/.ssh/authorized_keys <<EOL
${pubkey}
EOL
echo ${pubkey}
echo 'public_key added'
echo 'change user permision to ${username}'
sudo chown ${username}:${username} /home/${username}/.ssh/authorized_keys
echo ' everything is complet now login using the new user with the ssh default port 22'
echo 'deleting add_user_ubunto.sh'
echo 'if you like this script dont forget to spread the word and give a beer to this man.'
echo 'my paypal https://paypal.me/freelancerdad'
echo 'run this in your local machine'
IP=$(curl http://checkip.amazonaws.com)
echo "type ssh ${username}@${IP} into your local machine to login"
sudo rm add_user_ubunto.sh