Skip to content

Instantly share code, notes, and snippets.

@Ollie-Boyd
Last active August 31, 2026 22:41
Show Gist options
  • Select an option

  • Save Ollie-Boyd/f19c6e0ef34b1d5dba69f59467110581 to your computer and use it in GitHub Desktop.

Select an option

Save Ollie-Boyd/f19c6e0ef34b1d5dba69f59467110581 to your computer and use it in GitHub Desktop.
grep -rn -i "permitrootlogin" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/ 2>/dev/null
echo ---FIXING---
sed -i -E 's/^[[:space:]]*PermitRootLogin[[:space:]]+.*/PermitRootLogin prohibit-password/I' /etc/ssh/sshd_config
find /etc/ssh/sshd_config.d/ -type f -exec sed -i -E 's/^[[:space:]]*PermitRootLogin[[:space:]]+.*/PermitRootLogin prohibit-password/I' {} \; 2>/dev/null
echo ---VERIFY-CONFIG---
sshd -t 2>&1 && echo CONFIG_OK
echo ---RESTART---
systemctl restart ssh 2>&1 || systemctl restart sshd 2>&1
sleep 1
systemctl is-active ssh 2>&1 || systemctl is-active sshd 2>&1
echo ---RECHECK---
sshd -T 2>&1 | grep -i permitrootlogin
echo DONE_FIX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment