Last active
August 31, 2026 22:41
-
-
Save Ollie-Boyd/f19c6e0ef34b1d5dba69f59467110581 to your computer and use it in GitHub Desktop.
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
| 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