4.7.3.15 Ensure sshd PermitRootLogin is disabled

Warning! Audit Deprecated

This audit has been deprecated and will be removed in a future update.

View Next Audit Version

Information

The PermitRootLogin parameter specifies if the root user can log in using SSH. The current default is prohibit-password

Disallowing root logins over SSH requires system admins to authenticate using their own individual account, then escalating to root This limits opportunity for non-repudiation and provides a clear audit trail in the event of a security incident.

Solution

#!/usr/bin/ksh
PREFERRED_SETTING="no"
umask 077
set $(/usr/bin/egrep "^PermitRootLogin" /etc/ssh/sshd_config)
echo $?
if [[ ! -z $1 ]]; then
# Look for a setting and change to no if anything else
if [[ $2 != ${PREFERRED_SETTING} ]]; then
sed "s/^PermitRootLogin {1}[^ ]{1,}/PermitRootLogin ${PREFERRED_SETTING}/" /etc/ssh/sshd_config >/tmp/sshd_config.$$
fi
else
# Look for a comment and append
sed "/^# {0,}PermitRootLogin/ a^JPermitRootLogin ${PREFERRED_SETTING}/" /etc/ssh/sshd_config >/tmp/sshd_config.$$
fi

if [[ -e /tmp/sshd_config.$$ ]]; then
diff -u /tmp/sshd_config.$$ /etc/ssh/sshd_config
rm /tmp/sshd_config.$$
elif
# Verify setting is specified
/usr/bin/egrep "^PermitRootLogin" /etc/ssh/sshd_config >>/dev/null
if [[ $? -ne 0 ]]; then
print "PermitRootLogin ${PREFERRED_SETTING}" >> /etc/ssh/sshd_config
fi
fi

Re-cycle the sshd daemon to pick up the configuration changes:

stopsrc -s sshd
sleep 5
startsrc -s sshd

Impact:

The level 1 recommendation does not

require

a setting of no - setting the attribute to no requires either sharing a root password (to use su ), the installation of sudo or a configuration using extended RBAC for actions that require enhanced privileges.

Level 2 recommendation is to align with other Benchmarks that set PermitRootLogin to no

See Also

https://workbench.cisecurity.org/benchmarks/10385