How to Restrict and Monitor root Logins

This method immediately detects root attempts to access the local system.

  1. View the CONSOLE entry in the /etc/default/login file.

    Note:

    If you are using the account-policy SMF stencil and the config/etc_default_login property is enabled, you must view and change the login_policy/root_login_device property. For examples, see the procedures in Modifying Rights System-Wide As SMF Properties in Securing Users and Processes in Oracle Solaris 11.4. See also the account-policy(8S) man page.

    CONSOLE=/dev/console

    By default, the console device is set to /dev/console. With this setting, root can log in to the console. root cannot log in remotely.

  2. Verify that root cannot log in remotely.

    From a remote system, try to log in as root.

    system2 $ ssh -l root system1
    Password: Type root password of system1
    Password:
    Password:
    Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive).

    In the default configuration, root is a role, and roles cannot log in. Also, in the default configuration the ssh protocol prevents root user login.

  3. Monitor attempts to become root.

    By default, attempts to become root are printed to the console by the SYSLOG utility.

    1. Open a terminal console on your desktop.
    2. In another window, use the su command to become root.
      $ su -
      Password: Type root password
      #

      A message is printed on the terminal console.

      Sep 7 13:22:57 system1 su: 'su root' succeeded for jdoe on /dev/pts/6

Example 3-5 Logging root Access Attempts

In this example, root attempts are not being logged by SYSLOG. Therefore, the administrator is logging those attempts by removing the comment from the #CONSOLE=/dev/console entry in the /etc/default/su file.

# CONSOLE determines whether attempts to su to root should be logged
# to the named device
#
CONSOLE=/dev/console

When a user attempts to become root, the attempt is printed on the terminal console.

SU 09/07 16:38 + pts/8 jdoe-root

Troubleshooting: To become root from a remote system when the /etc/default/login file contains the default CONSOLE entry, users must first log in with their user name. After logging in with their user name, users then can use the su command to become root.

If the console displays an entry similar to Last login: Thu Sep 7 15:13:11 2017 from system2, then the system is configured to permit remote root logins. To prevent remote root access, change the #CONSOLE=/dev/console entry to CONSOLE=/dev/console in the /etc/default/login file. To find out how to return the ssh protocol to the default, see the sshd_config (5) man page.