Skip to content

Instantly share code, notes, and snippets.

@amit
Created September 15, 2017 18:24
Show Gist options
  • Save amit/8fed2f136efc33ffd4efa60e2b08efd5 to your computer and use it in GitHub Desktop.
Save amit/8fed2f136efc33ffd4efa60e2b08efd5 to your computer and use it in GitHub Desktop.
Check SSHD Configuration for Root User Login
#!/bin/bash
# This script checks if the root user can access SSH server on this machine
FILE="/etc/ssh/sshd_config"
if ! [[ -r $FILE ]]
then
echo "Unable to read $FILE"
exit 1
fi
# Take one check all lines
output=`grep PermitRootLogin $FILE `
# Take two - ignore all comments
output=`grep PermitRootLogin $FILE | grep -v '^\s*#' `
# Better alternative is to split the output and analyze second part (awk)
if echo $output | grep -i no
then
echo "PermitRootLogin is set to no! -- GOOD"
else
echo "Check $FILE for PermitRootLogin. Current setting is $output"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment