Last active
August 29, 2015 14:23
-
-
Save Manouchehri/1308a0780384d1447d2f to your computer and use it in GitHub Desktop.
Secure SSH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wget -O - https://gist***/lockdown.sh | bash | |
# Lock down SSH | |
sshport=$(shuf -i 49152-65000 -n1) && | |
sed -i "s/Port 22/Port $sshport/; s/PermitRootLogin yes/PermitRootLogin no/; s/#PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config && | |
# Get wordlist | |
apt-get update && | |
apt-get install -y wamerican && | |
username=$(echo $(shuf -n1 /usr/share/dict/words | tr -dc A-Za-z0-9)$(shuf -n1 /usr/share/dict/words | tr -dc A-Za-z0-9) | tr '[:upper:]' '[:lower:]') && | |
adduser $username --gecos "" --disabled-password && | |
adduser $username sudo && | |
echo "$username ALL=(ALL) NOPASSWD:ALL" | (EDITOR="tee -a" visudo) && | |
sudo -u $username sh -c "mkdir /home/$username/.ssh/ && | |
wget https://raw.githubusercontent.com/Manouchehri/dotfiles/master/.ssh/manouchehri.pub -O - >> /home/$username/.ssh/authorized_keys && echo >> /home/$username/.ssh/authorized_keys && | |
chmod 700 /home/$username/.ssh && chmod 600 /home/$username/.ssh/*" && | |
printf "To login:\nssh -l $username -p $sshport $(hostname -i)" && | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment