Skip to content

Enable SSH Print Last Log

An XCCDF Rule

Description

Ensure that SSH will display the date and time of the last successful account logon.
The default SSH configuration enables print of the date and time of the last login. The appropriate configuration is used if no value is set for PrintLastLog.
To explicitly enable LastLog in SSH, add or correct the following line in /etc/ssh/sshd_config:

PrintLastLog yes

Rationale

Providing users feedback on when account accesses last occurred facilitates user recognition and reporting of unauthorized account use.

ID
xccdf_org.ssgproject.content_rule_sshd_print_last_log
Severity
Medium
References
Updated



Remediation - Ansible

- name: Enable SSH Print Last Log
  block:

  - name: Check for duplicate values
    lineinfile:
      path: /etc/ssh/sshd_config

Remediation - Shell Script

# Remediation is applicable only in certain platforms
if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then

if [ -e "/etc/ssh/sshd_config" ] ; then
    
    LC_ALL=C sed -i "/^\s*PrintLastLog\s\+/Id" "/etc/ssh/sshd_config"