TL;DR: Installing SSH inside a container usually adds unnecessary overhead and expands the attack surface, according to StrongDM’s tutorial on how to execute commands in Docker containers with docker run and docker exec. For IAM and platform teams, the takeaway is that container access should stay scoped to the task, not to a persistent login pattern.
At a glance
What this is: This tutorial shows three ways to run commands in Docker containers and concludes that built-in Docker access is usually preferable to adding SSH.
Why it matters: It matters because container access design affects how identity, privilege, and operational scope are controlled across NHI, autonomous, and human administration paths.
👉 Read StrongDM's tutorial on SSH access patterns for Docker containers
Context
Docker container access is a governance problem as much as an operations problem. A container is intentionally minimal, so the control question is not whether SSH is possible, but whether adding it changes the access model in ways that outlive the task. For IAM and platform teams, the key issue is where privileged access is initiated, who can use it, and whether the session is tied to a narrow operational purpose.
The article argues that docker run and docker exec already provide an SSH-like workflow for most administration needs. That makes the real decision about identity scope, not convenience. If you need a persistent login path, you are no longer just managing a container command path. You are creating a broader access surface that should be governed like any other privileged execution path.
Key questions
Q: How should teams access Docker containers without creating unnecessary SSH exposure?
A: Use Docker-native commands such as docker run and docker exec for routine administration. They keep the interaction tied to the container lifecycle and avoid adding a separate remote login service, which broadens the attack surface and complicates credential and network governance.
Q: When does SSH inside a container become a governance problem?
A: SSH becomes a governance problem when it turns a disposable workload into a persistent remote administration target. At that point, the team has added new authentication, network exposure, and lifecycle obligations that are not present in the container’s default access model.
Q: What do teams get wrong about container debug access?
A: They often treat convenience as if it were neutral. In practice, direct login paths change the trust boundary, make access harder to review, and encourage standing administrative expectations that do not fit ephemeral infrastructure.
Q: What is the difference between Docker exec and SSH for container administration?
A: Docker exec attaches a command session through Docker’s control plane, while SSH creates a separate remote shell service inside the container. The first preserves the workload’s minimal design, while the second adds a durable access path that should be justified and governed separately.
Technical breakdown
Docker run versus docker exec for container access
docker run starts a new container instance and can place an operator directly into an interactive shell, while docker exec attaches a command session to a container that is already running. Both methods use Docker-native control paths rather than introducing a separate remote-login service. In practice, this keeps the access boundary aligned with the container lifecycle and avoids turning every debugging session into a standing access mechanism. The difference matters because command execution inside a container is not the same as authenticated server administration. The former is task-scoped container interaction, the latter is broader host-like access semantics.
Practical implication: prefer Docker-native command execution first, and treat SSH only as an exception requiring explicit governance review.
Why SSH inside a container expands the access surface
Installing OpenSSH in a container changes the control model by adding a persistent network service to something that was designed to be short-lived and minimal. That introduces new authentication handling, network exposure, package lifecycle management, and a broader set of paths an attacker or operator can use. It also weakens the clean separation between the container’s application role and its administrative role. From an identity standpoint, the container now behaves more like a managed server than an ephemeral workload. That is a meaningful architectural shift, even if the commands inside the session look the same.
Practical implication: if SSH is introduced, document it as an explicit exception and review the resulting network and credential exposure.
Container IP discovery and direct connection risk
Using docker inspect to retrieve the container IP enables direct connectivity, but it also exposes the fact that the operator is now relying on network reachability rather than the Docker control plane. Once a container is reachable by IP, access governance depends more on transport controls, credential management, and external network policy. That is a different trust boundary from executing commands through the host. For many teams, this is the point where debugging convenience starts to behave like durable remote administration. The operational shortcut becomes an identity and exposure decision.
Practical implication: review whether IP-based container access is actually required, and restrict it to tightly controlled troubleshooting workflows.
Breaches seen in the wild
- DeepSeek breach — DeepSeek breach exposed 1M+ log lines and sensitive secret keys.
- Azure Key Vault privilege escalation exposure — Azure Key Vault Contributor role misconfiguration enabled privilege escalation.
Read our 52 NHI Breaches Analysis report for a comprehensive view of breaches impacting Non-Human Identities including AI Agents.
NHI Mgmt Group analysis
Container SSH is usually a scope-expansion decision, not an access improvement. The article frames SSH as an option, but from an identity governance perspective it moves the container away from its intended minimal trust model. The practical question is not whether SSH works, but whether the workload should ever be granted a persistent login surface at all. That distinction matters because scope grows faster than most teams review it.
Least privilege for containers is easier to preserve when access stays inside Docker-native controls. docker run and docker exec preserve a narrower operational boundary than adding an SSH daemon. The moment an operator installs a remote shell inside the container, the access pattern starts to resemble server administration instead of ephemeral workload interaction. Teams should treat that as a governance change, not just a technical convenience.
Persistent container access creates identity drift between the workload and the operator. The container is built to be disposable, but SSH encourages a model in which administrators expect continuity, loginability, and repeatable remote presence. That drift makes recertification, logging, and privilege scoping harder because the access path no longer matches the workload’s design assumptions. Practitioners should recognise this mismatch before it becomes a standard operating pattern.
SSH in Docker is a reminder that operational shortcuts often become control exceptions. The article’s own logic shows that built-in tooling already solves most use cases. Once teams choose the heavier path, they inherit extra credential handling, broader network exposure, and a larger review burden. The implication is simple: normalise exception handling only when the operational requirement truly exceeds Docker-native access.
Container administration should be governed as temporary task access, not durable remote login. That is the cleanest way to preserve the security benefits of containerisation while still supporting debugging and remediation. IAM and platform teams should design approval and review processes around the access pattern they actually want, not the one that is easiest to reach in a hurry.
From our research:
- 4.6% of all public GitHub repositories contain at least one hardcoded secret, according to The State of Secrets Sprawl 2025.
- Public secret exposure is not rare in adjacent DevOps workflows, with 15% of commit authors having leaked at least one secret in their contribution history.
- For the broader control picture, Ultimate Guide to NHIs , Key Challenges and Risks explains why over-privilege and unmanaged credentials remain the recurring failure mode.
What this signals
SSH inside containers is usually a symptom of access sprawl, not a required operating pattern. As teams standardise container debugging, they should prefer controls that preserve the workload’s ephemeral boundary and avoid turning one-off troubleshooting into standing remote access. The governance question is whether the organisation can keep the administration path as narrow as the workload itself.
The operational pressure to make containers feel like servers often pushes teams into broader identity assumptions than their platform can safely support. That is where container debugging begins to resemble privileged infrastructure access, which means review, logging, and exception handling all need to tighten at the same time.
For teams already using secrets-heavy DevOps pipelines, the lesson is to stop treating convenience channels as low-risk by default. The more a container starts to behave like a long-lived endpoint, the more it needs the same access discipline used for other privileged systems, including explicit scope and review windows.
For practitioners
- Prefer Docker-native command execution first Use docker run and docker exec for routine troubleshooting so operators do not create a separate SSH-based administration path for every container. Keep that pattern as the default for ephemeral debugging and limit it to the host-managed control plane.
- Treat container SSH as an exception If an OpenSSH server is installed in a container, document the business reason, the approval path, and the conditions for removal. Review the added service, package, and network exposure before the exception is accepted.
- Restrict IP-based container access paths If teams use docker inspect to connect directly by container IP, constrain that access to tightly controlled troubleshooting windows and dedicated network segments. Do not let direct reachability become the standard operating model.
- Align debugging access with workload lifespan Match the duration and scope of admin access to the container’s intended lifetime, especially when the container is meant to be disposable. Avoid turning a short-lived workload into a long-lived remote endpoint.
Key takeaways
- Docker-native access keeps container administration closer to the workload’s intended lifecycle than SSH does.
- Adding SSH inside a container expands the access surface and creates extra governance obligations around credentials, logging, and network exposure.
- Teams should treat container remote access as an exception path that requires justification, not as a default debugging pattern.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-03 | SSH in containers affects credential handling and access duration. |
| NIST CSF 2.0 | PR.AC-4 | Container admin paths need least-privilege access control and review. |
| NIST Zero Trust (SP 800-207) | PR.AC | Direct IP access and SSH both change trust boundaries in runtime access. |
Verify container access through the narrowest viable control plane and avoid implicit trust in network reachability.
Key terms
- Container access boundary: The access boundary is the point at which a container stops being an isolated workload and starts behaving like a remotely managed system. In practice, that boundary shifts when teams add SSH, direct IP reachability, or persistent login expectations to an otherwise ephemeral container.
- Docker-native administration: Docker-native administration means executing operational commands through Docker’s own control paths, such as run and exec, instead of adding a separate remote shell service. This approach keeps access closer to the workload lifecycle and usually preserves a narrower privilege model.
- Persistent login surface: A persistent login surface is any access method that allows repeated remote entry beyond the immediate task need. For containers, SSH is the classic example because it adds a long-lived authentication and network path to something that was designed to be disposable.
- Ephemeral workload governance: Ephemeral workload governance is the discipline of controlling short-lived compute with access rules that match its short lifespan. It focuses on keeping identity, credentials, and administrative reach tightly scoped so the workload does not accumulate server-like privilege over time.
Deepen your knowledge
Container access scope, workload lifecycle, and least-privilege administration are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If your team is deciding when a container should stay ephemeral and when it starts behaving like a managed server, this course is a strong fit.
This post draws on content published by StrongDM: How to SSH into Docker Containers [Tutorial]. Read the original.
Published by the NHIMG editorial team on 2025-06-25.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org