Privilege escalation alerts in Zsh are your frontline defense against unauthorized access. They signal when a command, script, or process attempts to gain root or elevated permissions. Left unchecked, these events can open direct paths to system compromise. Zsh’s flexibility makes it powerful, but also a prime surface for privilege misuse.
To configure privilege escalation alerts in Zsh, start by enabling command logging. Use setopt HIST_IGNORE_DUPS and setopt HIST_SAVE_NO_DUPS to keep history clean. Pair this with real-time monitoring via tools like sudo's built-in logging or auditd rules for exec events. Create alert triggers that listen for sudo, doas, or environment changes to $PATH and $LD_PRELOAD. Pipe critical output to syslog, then push notifications through your preferred channel—Slack, email, or a SIEM platform.
For high-security environments, implement hooks in preexec to detect escalation attempts before they run. Combine this with signature checks on scripts in your PATH. Track SUID or SGID file changes using find / -perm -4000 on a scheduled interval, and generate instant alerts inside Zsh when new elevated binaries appear.