GIT_SSH_COMMAND is an environment variable that tells Git which SSH command and options to use for remote operations. It can override the default SSH client invocation, allowing settings such as identity files, ports or host key options to be applied per command.
What it does and why it matters
GIT_SSH_COMMAND is a per-invocation control for Git’s SSH transport. It changes the SSH client command Git launches for remote fetch, pull, push or clone operations, which makes it useful for applying temporary options without changing global SSH configuration.
That flexibility is powerful, but it also means a build script, developer shell profile or CI job can silently change how Git authenticates to a remote host. In practice, the term sits at the boundary between source control workflow and connection security, because the command string can alter identity files, ports, host key handling and other SSH behaviour.
How Git uses it during remote operations
Git reads this environment variable only when it needs to invoke SSH for a remote repository. The value can include a command name plus arguments, so it can point Git at an alternate SSH binary or add transport options that affect a single command execution.
Because the override is evaluated at runtime, it is often used in scripts, local debugging sessions and ephemeral automation. That makes it different from a persistent SSH config file: the effect is narrower in scope, but also easier to miss when troubleshooting why a repository suddenly connects on an unusual port or with a different identity file.
It is especially relevant when different remotes require different trust assumptions. For example, one Git host may need a non-default key or a pinned host key policy, while another uses ordinary system SSH settings. The variable lets a user express that difference without rewriting broader SSH configuration.
Security implications and failure modes
GIT_SSH_COMMAND can reduce friction, but it can also bypass established SSH defaults if it is set carelessly. A malformed command string can break repository access, while a deliberately altered one can weaken host verification or point Git at a key that was never intended for that remote.
It also creates an injection surface in scripts that interpolate untrusted input into the command string. If the variable is constructed from parameters rather than fixed text, a seemingly simple transport tweak can become a way to change the executed SSH command itself.
For that reason, the variable should be treated as security-sensitive configuration, not just developer convenience. Any place that sets it is effectively influencing how credentials, host trust and transport options are applied for the operation.
When to use it, and when to prefer a fixed SSH setup
GIT_SSH_COMMAND is best used for short-lived, explicit cases where the transport needs are well understood and tightly scoped. It is a practical choice for one-off operations, temporary debugging, or controlled automation where the command line is fully owned by the operator.
For repeatable team workflows, a dedicated SSH config entry or repository-specific operational standard is usually easier to audit. That keeps the connection policy visible outside the command invocation and reduces the chance that hidden environment state changes the way Git authenticates to a remote.
If the command is used in automation, the safest pattern is to keep the value static, quote it carefully, and limit which jobs or users can set it. That preserves the flexibility of the override without turning every Git call into an implicit transport-policy decision.
Risk and Threat Considerations
Because GIT_SSH_COMMAND controls the exact SSH invocation, it can be abused to redirect trust, change key usage, or bypass expected connection behaviour in scripts and build jobs. The main risk is not Git itself, but the fact that a hidden environment override can silently alter how a remote repository is reached and authenticated.
Failure mechanism: A local or pipeline-controlled environment value replaces the normal SSH client path and arguments, so the operation runs with different host key checks, identity material, or network destination than the operator expects.
Impact: That can cause unauthorized repository access, exposure of private keys or sessions to the wrong endpoint, or subtle supply-chain compromise if a clone or fetch is redirected to an untrusted host.
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 surface, CIS Controls v8 and NIST SP 800-53 Rev 5 set the technical controls, and ISO/IEC 27001:2022 defines the regulatory obligations.
| Framework | Control / Reference | Relevance |
|---|---|---|
| CIS Controls v8 | CIS-5 — Account Management | Controls which accounts and keys are used for remote access paths. |
| Recommendation — Restrict and review which accounts and keys automation may use for Git-over-SSH. | ||
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | Covers lifecycle and handling of SSH keys used by Git connections. |
| AC-6 — Least Privilege | Applies when command overrides grant broader remote access than intended. | |
| Recommendation — Manage SSH keys as authenticators with issuance, rotation and revocation controls. Limit Git execution contexts so they can only use the SSH options they need. | ||
| ISO/IEC 27001:2022 | A.5.15 — Access Control | Governance over who can change connection and authentication settings. |
| Recommendation — Require approval and review for environment-based overrides that affect remote access. | ||
| MITRE ATT&CK | T1552 — Unsecured Credentials | Relevant where SSH keys or connection material are exposed through overrides or scripts. |
| Recommendation — Hunt for scripts and jobs that expose or misuse SSH keys during Git operations. | ||
Practitioner Guidance
Why practitioners should care: This variable is a powerful override, so the question is not whether it works, but whether its use is intentional and reviewable. In automation, hidden transport overrides are hard to spot during incident review and can become a persistence mechanism for bad assumptions about where Git is really connecting.
What to watch for: Review scripts, CI jobs and wrapper commands for exported SSH overrides, especially where repository access starts failing, host keys change unexpectedly, or Git begins using an unexpected key, port or remote endpoint. Treat any dynamic construction of the value as a code-review item, not a convenience detail.
Related resources from NHI Mgmt Group
- What breaks when a git push can trigger backend command execution?
- Why can deleting a Git repository directory create command execution risk when other Git operations are still available?
- Why do Git integrations in developer tools create command execution risk?
- How do SSH keys and directory services work together for Git access control?
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 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org