Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.


Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.


Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.


Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Featured, Security

Finding Passwords in Logs and Shell History

Submitted by on June 27, 2019 – 11:15 am

Sooner or later it will happen: you type something after which you expect a password prompt then, without looking, you type the password. However, you fat-fingered the first command, and your password ended up in clear text in your shell history, maybe the system log, and who knows what remote syslog server.

Logs live forever. I’ve seen servers with logs that were older than the server (probably copied from the old server for some reason). With the help from remote syslog and various real-time indexers like Splunk or Graylog, logs are almost indestructible. Access to log data is generally poorly controlled with read permission granted to everyone more often than not.

All these reasons, combined with the fact that people make mistakes, make log files a valuable source of information for the hackers. It may seem that extracting strings that might be passwords from log data would be very challenging and time-consuming. Not so. Standard requirements for password strength make this task much more manageable.

Here’s a simple example to illustrate this point. Is this string a password: password? What about this one: P@ssw0rd1? See my point? Good, let’s continue.

Below is the script (also on GitHub) you can run on just about any modern Linux server to check users’ .bash_history and /var/log/messages for possible passwords. Naturally, you need to be root to do this. You can modify the script to only look at log files you can access with your credentials.

[su_spoiler title=”The script” icon=”arrow-circle-1″] [/su_spoiler]

If you’re a sysadmin and have access to configuration management tools like Salt or Ansible, you can run this script on multiple systems in parallel. Here’s an example of running the script via Salt CLI:

And below is sample output. The first three lines look like the user accidentally copy-pasted into command line an encryption key or somesuch. But the other four lines clearly contain two very stupid passwords for which jjames will receive a beating.

[su_spoiler title=”Sample output” icon=”arrow-circle-1″] [/su_spoiler]


Print Friendly, PDF & Email

Leave a Reply