Linux: Authorization, Authentication, and Accounting
Local Authentication
PAM (Pluggable Authentication Modules)
PAM handles the core authentication process: validating usernames, password, and enforcing policies. PAM relies on other modules to handle specific part of the authentication process. These modules are configured in files located in /etc/pam.d/
directory.
PAM module types
auth
: verifies user identityaccount
: enforces access policiespassword
: handle password updatessession
: manages tasks that happen at the start or end of a session
PAM uses controls flags to determine how each module's result should affect the overall outcome.
Module flags:
required
: the module must pass, processing continues even if it failsrequisite
: the module must pass, failure causes immediate terminationsufficient
: success means authentication may succeed early if no required module failedoptional
: only evaluated if it's the only module in the group
Polkit (PolicyKit)
Polkit manages authorization: deciding if regular users can perform administrative or system-level actions without switching to root. The rules are configured in files in /etc/polkit-1/rules.d/
or /etc/polkit-1/localauthority/
directories.
Directory-based Identity Management
Kerberos
Kerberos handles secure authentication using a ticket-based system to prove identity without repeatedly sending passwords. It is a secured network authentication protocol that allows users and services to prove their identity without sending passwords over the network.
LDAP (Lightweight Directory Access Protocol)
LDAP provides a structured directory for storing user accounts, groups memberships, and organizational information. It is a standardized protocol used to access and manage directory information. It is where the usernames, group definitions, and user attributes are stored.
SSSD (System Security Service Daemon) and Winbind
SSSD and Winbind act as intermediary on Linux for connection and using these centralized services seamlessly.
Network / Domain Integration
realm
realm
is a tool that simplifies the process of joining systems to domains and sets up authentication with minimal manual configuration. realm enables identity and login integration with Windows domains, but it doe snot handle file or printer sharing.
ex:
realm discover my.domain.com # to discover domains
realm join --user=admin my.corporation.com # to join my.corporation.com domain using the admin credentials
realm list # verify the configurations
realm permit --all # to permit all users to login
realm permit admin@my.domain.com # to allow specific user to login
realm permit -g "Administrators" # to allow a group to login
realm leave my.domain.com # to leave a domain
Samba
Samba provides a deeper integration with Windows environments. It is focussed on file sharing, printer access, and Windows-compatible network services. The main configuration is located in /etc/samba/smb.conf
example file share:
[global]
workgroup = WORKGROUP
server string = Samba Server
security = user
[Public]
path = /srv/samba/public
browsable = yes
writable = yes
guest ok = yes
udo systemctl start smb nmb # to start samba service
sudo systemctl enable smb nmb # tp enable samba a system start
Logging
/var/log
/var/log
is the central directory on most Linux systems where log files are stored.
messages
General system messages/var/log/syslog
System-wide log/var/log/kern.log
Kernel-specific messages/var/log/auth.log
//var/log/secure
Authentication and authorization events/var/log/boot.log
Boot process messages/var/log/dmesg
Kernel ring buffer messages/var/log/cron
Cron job execution logs/var/log/maillog
//var/log/mail.log
Mail server logs/var/log/Xorg.0.log
//var/log/X server
graphical session logs/var/log/apt/
//var/log/yum/
Package manager logs/var/log/journal/
Systemd journal storage
rsyslog
rsyslog
is a high-performance logging service that receives and stores log messages from the kernel, services, and applications. The configurations are stored in /etc/rsyslog.conf
and /etc/rsyslog.d/*.conf
ex:
auth.* /var/log/auth.log # to store all authentication messages to a file
kern.warning /var/log/kern.log # to log only kernel warning messages and above
*.* @@log.server.com:514 # to send log messages to a remote server
Message severity levels
emerg # system unusable
alert # immediate action required
crit # critical conditions
err # errors
warning # warnings
notice # normal but significant
info # informational messages
debug # debug messages
journalctl
journalctl
is a systemd tool used to view messages store by systemd journal.
journalctl -b # to view all logs for the current boot
journalctl -b -1 # to view all logs for the previous boot
journalctl -f # to tail log
journalctl -k # to view logs from the kernel
journalctl -u nginx.service # to view logs nginx
logrotate
logrotate
is a tool for managing the size and rotation of log files, ensuring that logs do not fill up the disk over time. The main configuration is located in /etc/logrotate.conf
and /etc/logrotate.d/
.
ex:
logrotate -d /etc/logrotate.conf # to check configuration
logrotate -f /etc/logrotate.conf # to force log rotation
System Audit
auditd
auditd
is a service that records audit events to disk, and administrators control i witht he systemd utility.
audit.rules
audit.rules
is the configuration file that tells the audit subsystem precisely which activity to record. The configuration is located in /etc/audit/rules.d/audit.rules
.
ex:
-w /etc/passwd -p wa -k passwd_changes # to tell the audit system to watch for password changes
-w /var/log/lastlog -p wa -k login_logs # to watch for user login
-w /var/run/faillock -p wa -k failed_logins # to watch for failed logins
ausearch -k passwd_changes # to search logs for keys