Last active
January 27, 2018 20:09
-
-
Save T4cC0re/5529c664723070a4dbb3 to your computer and use it in GitHub Desktop.
Secure SSH access (as root)
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
#/usr/bin/env bash | |
# this assumes you have installed your public key and have means to access to the server. | |
rm -rf /etc/ssh/ssh_host_* | |
ssh-keygen -A | |
passwd -d root | |
sed -i 's/^[# ]*PermitRootLogin [^\r\n\]\+$/PermitRootLogin without-password/gmi' /etc/ssh/sshd_config | |
sed -i 's/^[# ]*ServerKeyBits [^\r\n]\+$/ServerKeyBits 2048/gmi' /etc/ssh/sshd_config | |
sed -i 's/^[# ]*PermitEmptyPasswords [^\r\n]\+$/PermitEmptyPasswords no/gmi' /etc/ssh/sshd_config | |
sed -i 's/^[# ]*PubkeyAuthentication [^\r\n]\+$/PubkeyAuthentication yes/gmi' /etc/ssh/sshd_config | |
sed -i 's/^[# ]*PasswordAuthentication [^\r\n]\+$/PasswordAuthentication no/gmi' /etc/ssh/sshd_config | |
/etc/init.d/ssh restart || service ssh restart || systemctl sshd.service restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment