Bashrc persistence is a Linux persistence technique that abuses the shell startup file .bashrc to run commands each time an interactive Bash session starts. An attacker adds a command, alias or function to that file so malicious code executes under the user account whenever a new shell opens, giving repeat access without changing system binaries.
How Bashrc Persistence Works
Bashrc persistence is a Linux logon persistence method, but it is specifically tied to interactive Bash sessions rather than system boot. By placing a command, alias, or function in .bashrc, an attacker can make malicious code run whenever that user opens a new shell.
The technique is effective because .bashrc is a trusted convenience file, loaded automatically in many everyday terminal workflows. That means the malicious instruction can blend into normal administration or development activity and keep executing without altering a core binary or service.
Why Bashrc Persistence Is Dangerous
The danger is not just that code runs, but that it runs in a legitimate user context every time the shell starts. That can give an attacker repeated access, support command execution, and help maintain footholds across reboots, logouts, and routine terminal use.
Because the payload lives in a startup file, it can be easy to overlook during a quick compromise review. If the affected account is privileged, the impact can extend well beyond simple nuisance execution and become a durable path to further lateral movement or credential theft.
How Defenders Spot Bashrc Persistence
Exposure checks should start with user profile inventory, because persistence here depends on a writable shell startup file in an account the attacker can influence. Review home directories, dotfiles, and recent changes to .bashrc, especially where shell profiles are managed inconsistently across fleets.
Detection is strongest when file integrity signals are paired with behaviour analysis. Unexpected shell startup commands, unfamiliar aliases, or functions that invoke external scripts, downloaders, or encoded payloads are all indicators worth investigation. Persistence Techniques Guide covers this class of autostart methods in a broader detection and eviction context.
For broader adversary tradecraft, ATT&CK-style mapping helps defenders connect this technique to post-compromise objectives such as repeat execution and defence evasion. MITRE ATT&CK Enterprise Matrix is useful for that kind of hunt and response alignment.
How to Reduce and Remove Bashrc Persistence
Remediation usually means finding the injected line, alias, or function, removing it, and validating that no related payload remains in sibling startup files such as .profile or shell-specific equivalents. If the account was compromised, treat the file edit as one symptom, not the whole incident.
Compensating controls matter when cleanup is delayed or the account is shared. Tighten write permissions on profile files, monitor for dotfile changes, and consider harder shell startup governance for sensitive accounts. Identity Threat Detection and Response (ITDR) Guide is relevant when shell persistence is part of a larger identity compromise path.
When the persistence route was used to execute commands under a real user, review what that session could access, then reset any credentials, tokens, or secrets that may have been exposed during the compromise.
Risk and Threat Considerations
bashrc persistence is attractive because it hides in a routine user workflow and survives ordinary logouts. The main risk is durable, repeated code execution under a valid account, which can make a compromised host look normal while an attacker keeps re-entering through new shells.
Failure mechanism: The attacker abuses a trusted startup file, so every interactive Bash session becomes an execution trigger instead of a clean administrative shell.
Impact: This can preserve access, enable stealthy command execution, and extend the compromise to any data, tools, or secrets reachable by that account.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
MITRE ATT&CK addresses the attack and risk surface, while NIST SP 800-53 Rev 5, CIS Controls v8 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| MITRE ATT&CK | T1546.004 — Unix Shell Configuration Modification | Covers persistence via modifying shell startup files such as .bashrc. |
| Recommendation — Map shell-startup changes to T1546.004 and alert on unexpected dotfile edits. | ||
| NIST SP 800-53 Rev 5 | AU-6 — Audit Record Review, Analysis, and Reporting | Supports review of file and session activity to spot unauthorized shell startup changes. |
| CM-5 — Access Restrictions for Change | Applies because persistence depends on preventing unauthorized modification of startup files. | |
| Recommendation — Correlate shell profile changes with audit data to detect suspicious persistence edits. Restrict who can modify user startup files and validate every exception. | ||
| CIS Controls v8 | CIS-8 — Audit Log Management | Fits monitoring and review of file modifications and suspicious user-session behaviour. |
| Recommendation — Centralize and review dotfile change logs to catch unauthorized startup-file persistence. | ||
| NIST CSF 2.0 | DE.CM-01 — Monitoring for Unauthorized Devices, Connections, and Software | Supports continuous monitoring for unauthorized startup-file changes and malicious shell behaviour. |
| Recommendation — Monitor for unauthorized shell startup modifications and investigate unexpected execution paths. | ||
Related resources from NHI Mgmt Group
- When does malware persistence become an NHI governance issue?
- How do security teams know if persistence has been established on a compromised AI node?
- How should security teams prevent unwanted persistence in Active Directory and Entra ID?
- Why do stale accounts and old privilege create such a large persistence risk?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 29, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org