Development teams should keep access tokens out of plain text shell files and store them in an OS protected secret store instead. On macOS, that means Keychain. On Linux desktop, that means GNOME Keyring with libsecret and DBus. Bash then reads the token at runtime, reducing exposure if profiles, repositories, or terminals are inspected.
Why shell files are the wrong place for automation tokens
Shell files are convenient, but they are a poor storage boundary for secrets manager access tokens because they are easy to inspect, copy, commit, and inherit into other shells. A token that sits in a profile or script is exposed to the same risks as any other plaintext secret, so the practical goal is to keep the secret outside the file system representation of the automation itself.
That is why a runtime lookup model is safer. Bash can fetch the token only when it needs it, while the durable copy lives in an OS protected secret store rather than in a repository, dotfile, or shared terminal session.
For teams choosing the storage pattern, the important distinction is not whether the token exists, but where its at-rest copy is governed. A protected store gives you a smaller exposure surface than shell variables written into startup files, and it also makes later rotation and revocation easier to operationalise.
When this pattern is used well, the shell becomes a consumer of the secret, not a place where the secret is authored and left behind.
How to keep Bash access tokens out of plain text
Use the operating system’s secret storage and retrieve the token at execution time. On macOS, that means Keychain. On Linux desktop, that means GNOME Keyring with libsecret and DBus. In both cases, Bash should read the token only when the command runs, then pass it to the client process without writing it back to disk.
This approach works best when the token is treated as a bootstrap credential, not a long-term embedding in automation. If the script needs portability, prefer an environment-neutral retrieval step that is called from the shell rather than storing the value inside practical secrets management guidance. That keeps the secret separate from the code path that uses it.
If the team manages service tokens across multiple vendors, the same principle applies: store the token in the secret store, bind retrieval to the local user or workstation context, and avoid copying the value into launch scripts, login profiles, or ad hoc notes. For teams comparing options, the secrets management buyer’s guide is useful for checking whether the tool supports secure retrieval, rotation, and auditability.
Where the token is part of a broader secrets manager workflow, the storage choice should support the rest of the lifecycle too. Doppler, 1Password and Infisical service tokens are a good example of why scope, expiry, and leak detection matter as much as the storage location.
What changes when the token is read at runtime
Runtime retrieval changes the blast radius. A token kept out of shell files is less likely to be exposed through code review, shell history, backups, sync tools, or casual terminal inspection. It also makes it easier to separate the machine that stores the secret from the script that merely consumes it.
That separation matters because access tokens are bearer material. If an attacker or another user gets the value, the token can usually be replayed until it expires or is revoked. A design that hides the token in a protected local store does not remove that risk, but it does reduce the number of places the token can leak from.
This is also why token hygiene should be paired with rotation discipline. A local secret store protects exposure on the workstation, but it does not help if the token is long-lived, over-scoped, or copied into multiple automation paths. When teams need a reminder of the lifecycle risks, token and session security is the right mental model.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
NIST SP 800-53 Rev 5, CIS Controls v8 and OWASP ASVS set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | Covers secure handling and lifecycle of access tokens used by automation. |
| IA-9 — Service Identification and Authentication | Applies when scripts and services authenticate with tokens at runtime. | |
| Recommendation — Store, rotate, and revoke automation tokens under managed authenticator lifecycle controls. Use service authentication controls that avoid embedding shared tokens in shell files. | ||
| ISO/IEC 27001:2022 | A.5.15 — Access control | Relevant because token storage and retrieval should enforce controlled access to secrets. |
| Recommendation — Restrict who and what can retrieve automation tokens from the secret store. | ||
| CIS Controls v8 | CIS-5 — Account Management | Supports controlling non-human credentials and their lifecycle in automation. |
| Recommendation — Inventory automation credentials and remove any unused or overexposed tokens. | ||
| OWASP ASVS | V14 — Data Protection | Relevant because the token is sensitive data that must not be exposed in files or logs. |
| Recommendation — Protect sensitive tokens from disclosure in storage, logs, and runtime handling. | ||
Practitioner Guidance
What to prioritise: Move the token out of shell startup files first, then confirm the Bash job can still retrieve it non-interactively from the protected store. The main failure mode is usually not the retrieval call itself, but an unnoticed fallback that silently reintroduces plaintext storage.
What to verify: Check where the token can be read from on a real workstation, not just where it is intended to live. Verify that repository clones, dotfiles, shell history, and shared terminal sessions do not contain a usable copy, and that rotation does not require code changes.
Practitioner takeaway: Treat the shell as an execution layer, not a secret repository, and make the secret store the only durable source of truth for the token.
Related resources from NHI Mgmt Group
- What happens when an attacker gains shell access to a hardened secrets manager but cannot write files or execute new processes?
- How should security teams handle secrets in development toolchains without exposing credentials in plain text files?
- How should security teams implement credential access for browser-based AI agents without exposing secrets to the model?
- What is the difference between storing secrets in docker-compose files and injecting them at runtime from a secrets manager?
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 November 3, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org