Hide Linux User Sessions (Bash History Hacks)
Bash history is a convenience for users, not a reliable record of Linux activity. For accountable privacy, keep personal data access limited while recording authorized sessions with auditd, persistent system logs, and a separately managed collector. Test coverage, storage, and alerts before relying on them. I can’t help conceal sessions or suppress records, but this guide shows how to protect and verify them.
If your concern is that visible command history exposes sensitive details, the quick fix is not to erase records. Avoid typing passwords, tokens, or other secrets directly into commands; use approved secret-handling tools, and ask your administrator about access to logs. Then check whether your system records process activity outside the shell.
I treat this as two separate goals: limit who can read logs, and preserve an accurate record for authorized review. Bash history alone cannot prove that a command was or was not run. It can be changed by a user, may not capture every type of activity, and does not replace system auditing.
Planning the Audit and Retention Requirements
Audit planning sets what activity must be recorded, who may review it, and how long records must be kept. Start with the organization’s policy and the risks on each host. A useful plan balances evidence needs with the storage and system load that detailed logging can create.
Before changing configuration, survey the host:
- Identify interactive shells, service accounts, privilege boundaries, and ways users log in.
- Check whether
auditdis installed and running, and inspect existing rules before adding new ones. - Identify log destinations, disk capacity, rotation settings, and required retention.
- Ask which events matter for review, such as process execution, account changes, and session logins.
auditd records kernel audit events independently of Bash’s interactive history. That separation is useful, but it does not mean every keystroke or shell built-in becomes a distinct audit event. For example, a rule for execve records programs started through that system call; it does not create a separate process-execution record for every shell built-in.
Agree on a retention period and access policy before collecting more data. Requirements vary by organization and may depend on incident-response needs, applicable rules, and available storage. Do not set a retention period by guesswork. Record the decision, the person responsible for it, and how you will review it.
Access Boundaries and Log-Storage Capacity
Log protection means limiting who can read, change, or delete records, while keeping enough space for expected activity. Plan local permissions, retention, and central collection together. A log that fills its disk or stays only on a host under review may fail to meet your evidence needs.
Keep audit logs in their configured system location, commonly under /var/log/audit/, and restrict access through the distribution’s supported permissions and group policy. Avoid broadening access just to make review easier. Give reviewers only the access they need, and document who can administer the audit service.
Persistent systemd journal storage uses /var/log/journal. It can help retain system service messages across reboots, but it is separate from the audit log. To enable persistent journal storage, check the system’s journald configuration under /etc/systemd/journald.conf or its drop-in directory. Set Storage=persistent and choose size or time limits that match the host’s storage and retention needs. Apply changes using the method supported by your distribution.
Check current journal use with:
journalctl --disk-usage
Broad process-execution rules can create a large volume of records. Estimate storage using a test period that reflects normal and peak activity, then set rotation and retention limits accordingly. Monitor free disk space and alert on unexpected growth. A full filesystem can affect more than logging, so include the log partition or filesystem in routine capacity checks.
Configuring Auditing and Central Forwarding
Configure only the rules you need, test them before making them persistent, and confirm records reach a protected destination. Central forwarding adds a layer of protection if a local host is lost or tampered with. The exact file paths and service commands can vary by distribution, so check its documentation before applying changes.
First, inspect the current state:
systemctl status auditd
auditctl -s
auditctl -l
auditctl -s reports audit status, including whether auditing is enabled, the current backlog, the backlog limit, and the count of lost events. Save the initial output so you can compare it after testing. Do not assume that a running service means all desired rules are loaded.
For a system that supports the 64-bit ABI, a process-execution rule can be written as:
-a always,exit -F arch=b64 -S execve -k process_exec
If the host runs 32-bit programs, add the equivalent rule:
-a always,exit -F arch=b32 -S execve -k process_exec
These rules can generate substantial activity. Test them on a representative workload and review the resulting volume before broad deployment. Add account or session-event rules based on your requirements and the distribution’s guidance. PAM and login configuration affect which user and session details are available, so verify attribution rather than assuming it.
On systems using augenrules, persistent rules are often stored in /etc/audit/rules.d/ and loaded with:
augenrules --load
Use the distribution’s documented method to validate and load rules. Do not overwrite existing rules without reviewing them; a host may already have rules required by policy or other software.
| Control | What to check | Practical reason |
|---|---|---|
| Process rules | Expected execve rules appear in auditctl -l | Confirms the intended rule set is loaded |
| Audit status | enabled, backlog, and lost in auditctl -s | Shows operating state and possible event loss |
| Journal storage | journalctl --disk-usage and configured limits | Helps prevent unplanned disk pressure |
| Forwarding | Events arrive at the approved collector | Keeps a separate copy for review |
| Attribution | Test records show the expected user and time | Confirms events can be tied to a session |
Forward records to a separately administered collector using a supported, protected transport. Restrict collector access, define its own retention, and alert if forwarding stops. Central storage does not remove the need to monitor local audit health; forwarding can fail while local records continue, or local storage can fail before records reach the collector.
Audit immutable mode can prevent rule changes until reboot. The setting is:
-e 2
Use it only after the rules have been validated and you have planned how legitimate updates will be made. Place it as required by the system’s rule-loading process, often as the final rule. Test the full change and recovery process first; a mistaken immutable configuration can block rule changes until a reboot.
Verifying Coverage, Integrity, and Alerting
Verification checks that events are recorded, correctly attributed, retained, and forwarded. A configuration file alone is not proof of working coverage. Test with an authorized account, compare expected actions with audit records, and confirm that monitoring detects audit failure or lost events.
A safe validation sequence is:
- Record the current output of
auditctl -sandauditctl -l. - Start an approved test session and run a harmless external program, such as
id. - Search the audit log for the rule key:
bash
ausearch -k process_exec -i
- Confirm the event shows the expected account, time, and program details.
- Check the collector for the same event, then review disk use and
auditctl -sagain.
Treat any increase in the lost count as a problem to investigate. The acceptable operational target is no unexplained loss; do not treat a particular backlog value as a universal safe threshold. Tune the backlog based on measured workload, system capacity, and the response plan for audit pressure.
Monitor for audit-service failure, forwarding interruption, low disk space, and changes to audit configuration. Immutable mode can make rule changes harder during a running system, but it does not replace central copies or alerting. Root-level access and reboot remain important parts of the threat model, so protect administrative access and review who can control the host.
Two common deployment situations show why testing matters. These are examples, not claims about a particular organization:
- Small office server: An administrator adds execution rules and sees a growing audit log during routine software updates. The next step is to measure volume, tune rotation and retention, and confirm central forwarding before applying the rules to other servers.
- Shared research workstation: A test event appears locally but not at the collector. The team checks forwarding health and collector access, then repeats the test and verifies account attribution before calling the setup complete.
The key outcome is not a hidden session. It is a documented, tested record that authorized reviewers can use, with alerts when collection or storage fails.
Conclusion and FAQ
Reliable session accountability depends on more than Bash history. Plan the events and retention you need, protect logs from casual access, test audit rules and central forwarding, and watch storage and lost-event counts. Keep privacy through narrow access and careful handling of secrets, not by concealing activity.
Can Bash history prove that a command was run?
No. Bash history is not an authoritative audit trail and may be incomplete or changed.
Does auditd record every command typed into Bash?
No. An execve rule records program execution, not every shell built-in or keystroke.
What does auditctl -s show?
It reports audit status, including enabled state, backlog information, and lost-event count.
Should I add the 32-bit rule to every Linux host?
Add it when the host runs 32-bit programs and supports that ABI. Check your system’s requirements first.
What does -e 2 do?
It enables immutable audit mode until reboot, preventing rule changes while it is active. Test configuration and recovery before using it.
Does persistent journald replace audit logs?
No. Journald and the audit system are separate. Configure and verify each for its intended records.
How can I tell if the audit rules work?
Run an approved test, search for its event locally, and confirm the same record reaches the central collector with correct attribution.
What should I do if the lost-event count rises?
Investigate workload, backlog limits, and system capacity. Treat unexplained lost events as a gap, and do not rely on the affected period until reviewed.
Can central forwarding prevent all log tampering?
No. It provides a separately stored copy, but forwarding can fail and host administrators may still have powerful access. Monitor delivery and protect the collector.
How much storage do audit logs need?
There is no single safe size. Measure volume under representative load, set retention to policy, and alert on disk pressure and unexpected growth.
(This article was written by one of our staff writers, Richard Montclair. Visit our Meet the Team page.)






