Skip to content

Instantly share code, notes, and snippets.

@T4cC0re
Last active January 27, 2018 20:09
Show Gist options
  • Save T4cC0re/5529c664723070a4dbb3 to your computer and use it in GitHub Desktop.
Save T4cC0re/5529c664723070a4dbb3 to your computer and use it in GitHub Desktop.
Secure SSH access (as root)
#/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