Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- sleep 1
- # we need to be root
- if [ "$(id -u)" != "0" ]; then
- echo "Sorry! This script must be run as root." 1>&2
- exit 1
- fi
- # set timezone
- echo " * Updating apt and setting timezone..."
- apt-get update --yes
- apt-get dist-upgrade --yes
- apt-get autoremove --yes
- sudo timedatectl set-timezone Europe/London
- getent passwd khaled > /dev/null
- if [ $? -eq 0 ]; then
- echo "User khaled exists."
- else
- echo " * Creating standard user..."
- adduser khaled
- usermod -aG sudo khaled
- fi
- 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
- mkdir -p /home/khaled/.ssh
- chown khaled.khaled /home/khaled/.ssh/
- echo "$SSHKEY" > /home/khaled/.ssh/authorized_keys
- chown khaled.khaled /home/khaled/.ssh/authorized_keys
- 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
- 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
- sudo systemctl reload sshd
- echo " * Set Up a Basic Firewall..."
- sudo ufw allow OpenSSH
- sudo ufw enable
- # cleanup
- echo " * Cleaning up..."
- apt-get autoremove --yes
- apt-get clean --yes
- #echo "Enjoy your server"
Add Comment
Please, Sign In to add comment