Guest User

Untitled

a guest
Jan 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. sleep 1
  4.  
  5. # we need to be root
  6. if [ "$(id -u)" != "0" ]; then
  7. echo "Sorry! This script must be run as root." 1>&2
  8. exit 1
  9. fi
  10.  
  11. # set timezone
  12. echo " * Updating apt and setting timezone..."
  13. apt-get update --yes
  14. apt-get dist-upgrade --yes
  15. apt-get autoremove --yes
  16. sudo timedatectl set-timezone Europe/London
  17.  
  18. getent passwd khaled > /dev/null
  19. if [ $? -eq 0 ]; then
  20. echo "User khaled exists."
  21. else
  22. echo " * Creating standard user..."
  23. adduser khaled
  24. usermod -aG sudo khaled
  25. fi
  26.  
  27. read -r -p 'Paste in the public SSH key for the new user. You can get it using this command `cat ~/.ssh/id_rsa.pub`:' SSHKEY
  28. mkdir -p /home/khaled/.ssh
  29. chown khaled.khaled /home/khaled/.ssh/
  30. echo "$SSHKEY" > /home/khaled/.ssh/authorized_keys
  31. chown khaled.khaled /home/khaled/.ssh/authorized_keys
  32.  
  33. sudo grep -q "ChallengeResponseAuthentication" /etc/ssh/sshd_config && sed -i "/^[^#]*ChallengeResponseAuthentication[[:space:]]yes.*/c\ChallengeResponseAuthentication no" /etc/ssh/sshd_config || echo "ChallengeResponseAuthentication no" >> /etc/ssh/sshd_config
  34. sudo grep -q "^[^#]*PasswordAuthentication" /etc/ssh/sshd_config && sed -i "/^[^#]*PasswordAuthentication[[:space:]]yes/c\PasswordAuthentication no" /etc/ssh/sshd_config || echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
  35. sudo systemctl reload sshd
  36.  
  37. echo " * Set Up a Basic Firewall..."
  38. sudo ufw allow OpenSSH
  39. sudo ufw enable
  40.  
  41. # cleanup
  42. echo " * Cleaning up..."
  43. apt-get autoremove --yes
  44. apt-get clean --yes
  45.  
  46. #echo "Enjoy your server"
Add Comment
Please, Sign In to add comment