Challenge ·Medium

Shell History: Delete Sensitive Commands and Prevent Future Logging

Mister P
by  Mister P · on
Linux
Practice managing Bash history by removing a specific sensitive command from history and configuring the shell to prevent space-prefixed commands from being saved.

A junior sysadmin accidentally ran a command containing a secret API key, and the shell history now contains the string supersecret-api-key=abc123XYZ. You need to clean it up and make sure space-prefixed commands won't be logged in future sessions.

Complete the following tasks on rocky-01 as the laborant user:

  1. Remove the command containing supersecret-api-key=abc123XYZ from ~/.bash_history (leave all other history entries intact).
  2. Configure the shell so that commands prefixed with a space are not saved to history, and make this setting persistent across new login sessions.
Hint 1 — Finding the entry

Use history to display the numbered list of commands. Look for the line containing the secret string. Note its number.

Hint 2 — Removing a single history entry

history -d <number> removes a single entry by its line number. After deleting, write the updated history to disk.

Hint 3 — Writing history to disk

In-memory changes to history are not saved automatically. Use history -w to flush the current in-memory history to ~/.bash_history.

Hint 4 — Preventing space-prefixed commands from being logged

Set HISTCONTROL=ignoreboth (or ignorespace) in ~/.bashrc and source the file so the setting is active immediately. The ignorespace value tells Bash to skip saving any command that begins with a space character.