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 is a StrongDM tutorial arguing that Docker access should usually be handled with docker run or docker exec rather than installing SSH, because SSH expands container scope and persistence.
Why it matters: It matters because container access patterns shape operational blast radius, and IAM, PAM, and platform teams need to avoid turning a minimal workload into a standing access surface.
Context
Docker containers are designed to be minimal, single-purpose execution environments, which changes how access should be handled. When a team adds a full SSH service to that model, it is no longer only choosing a command path, it is adding a persistent login surface to an environment that was intended to stay constrained.
The governance question is not whether an administrator can get a shell. It is whether the access method preserves task scope, keeps the container footprint small, and avoids creating a new standing path that behaves more like server administration than container operations.
In NHI terms, the article sits at the boundary between workload access and operational convenience. The control problem is preserving a narrow execution path for container work while avoiding unnecessary identity and service expansion inside the workload itself.
Key questions
Q: What breaks when teams rely on SSH as the normal way to access Docker containers?
A: The container becomes harder to operate as a container and easier to mismanage like a server. You introduce service sprawl, extra configuration for keys and users, and a larger chance of inconsistent access patterns across environments. In practice, that slows debugging, increases maintenance, and weakens the simplicity that makes container operations predictable.
Q: Why does running SSH inside a container usually create more risk than it removes?
A: SSH inside a container adds another service, another attack surface, and another credential path to manage. It also encourages treating containers like virtual machines, which conflicts with the single-service model that makes containers easier to debug and secure. If remote access is needed, use the lightest method that meets the task, and avoid exposing port 22 unless there is a clear requirement.
Q: How should platform teams decide whether a container needs SSH at all?
A: Start from the operational goal and ask whether the same outcome can be achieved with docker run or docker exec. If it can, SSH is usually an unnecessary expansion of container scope. Only accept SSH when there is a documented requirement for a persistent remote access pattern that cannot be met by native Docker tooling.
Q: What should teams do when a container already has a standing login path?
A: Reassess the container's purpose, exposed services, and access boundaries, then determine whether the login path is actually required for support or whether it reflects inherited server habits. If it is not required, remove it and return the workload to a minimal, task-bound execution model.
Technical breakdown
Why docker run and docker exec preserve container scope
Docker provides native command execution paths that attach to a running container without turning it into a general-purpose server. docker run creates the container and opens an interactive session, while docker exec injects a command into an already running container. Both approaches keep access tied to the current task and avoid introducing a long-lived remote login service. That matters because a container is meant to be sparse, disposable, and narrowly functional. The access model should reflect that design rather than recreate the habits of VM administration.
Practical implication: use native Docker command execution first so the access path stays tied to the container task rather than the operator.
What changes when SSH is installed inside a container
Installing OpenSSH inside a container adds a separate network-reachable login service and usually requires additional configuration, including image changes and network discovery. That shifts the container from task-scoped execution toward persistent remote administration. It also broadens the attack surface because the workload now exposes an SSH service, credentials, and a new path for shell access. Even when the commands being run are the same, the access pattern is not. The control question is not command equivalence, but whether the remote session is now part of the workload's standing footprint.
Practical implication: treat SSH inside a container as a scope-expanding design choice, not as a neutral convenience feature.
Why persistent shell access conflicts with container minimalism
Container security depends on reducing what exists inside the image and what remains reachable at runtime. A built-in SSH server undermines that by adding packages, services, and a second operational pattern for the same admin task. The tutorial's own logic shows the tradeoff: if docker exec already delivers the needed shell, then SSH is duplication with governance cost. This is not merely about performance or clean architecture. It is about whether access remains ephemeral and narrow or becomes a standing administrative pattern inside a system that was built to stay small.
Practical implication: keep interactive access ephemeral unless there is a documented operational need that outweighs the additional service footprint.
NHI Mgmt Group analysis
SSH inside a container is an access-scope decision, not just an administration preference. The article makes the core tradeoff plain: docker exec already supports shell-like operations without adding a daemon and network service. Once SSH is installed, the container is no longer only a workload with command access, it becomes a remotely accessible login target. For identity teams, that changes the control boundary from task execution to standing access surface.
Container minimalism and persistent login services are in direct tension. Docker's value comes from narrow purpose, low footprint, and disposable runtime state. SSH works against that model because it introduces another identity-bearing service into the workload. That widens the number of places where credentials, access rules, and monitoring now matter. The practitioner implication is to treat any added service inside a container as a governance choice with blast-radius consequences.
Task-bound access is the right baseline for container operations. The article implicitly distinguishes between needing a shell and needing a remote administration pattern. That distinction matters because many access requests are really operational, not architectural. If the same outcome can be achieved through docker run or docker exec, then SSH is usually a redundant control path that weakens the containment model rather than strengthening it.
Identity scope should follow workload scope, not host-era habits. Teams still inherit server administration instincts when they reach for SSH, but containers are not full servers and should not be treated as such. The named concept here is scope tradeoff of SSH: every time a container gains a persistent login path, the workload's security model becomes harder to reason about. Practitioners should keep execution access as close as possible to the workload's original lifecycle boundary.
From our research library:
- Red Hat’s Kubernetes Security Report found that nearly 9 in 10 organizations had at least 1 container or Kubernetes security incident in the last 12 months.
What this signals
Scope creep is the real access problem here: once a container accepts SSH, the access model no longer mirrors the workload's intended minimal footprint. That makes review, monitoring, and operator discipline harder because the control boundary shifts from command execution to remote administration.
For platform and IAM teams, the practical signal is simple: if the same shell access is already available through Docker tooling, adding SSH usually increases governance burden without improving task execution. Keep the container's access model aligned to the work it actually performs.
For practitioners
- Prefer native Docker command execution Standardise docker run and docker exec for routine interactive operations so operators use the container's built-in execution path instead of a separate login service.
- Avoid installing SSH by default Treat OpenSSH as an exception that requires an explicit operational justification, because it adds packages, services, and a persistent access surface to the image.
- Review container access scope Check whether each container has become reachable through a standing administrative path that is broader than the task it is meant to perform.
- Keep workload images minimal Remove services and packages that do not support the container's primary function, especially where the same outcome is already available through Docker tooling.
Key takeaways
- Docker containers are intended to stay minimal, so adding SSH often changes the access model more than it changes the operator experience.
- The article's core distinction is between task-bound execution through Docker tooling and persistent login access through SSH.
- Teams should treat SSH inside a container as an exception that expands scope, not as a default admin 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 addresses the attack and risk surface, while NIST CSF 2.0 and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-06 — Insecure Cloud Deployment Configurations | Installing SSH changes the container's runtime exposure and weakens the intended deployment boundary. |
| NHI-05 — Overprivileged NHI | SSH creates broader access than the task usually requires, which is a scope problem for workload identity. | |
| Recommendation — Remove unnecessary login services from container images and keep deployment exposure aligned to workload purpose. Limit container access paths to the minimum required for the operation and avoid standing admin routes. | ||
| NIST CSF 2.0 | PR.AA-05 — Access Permissions, Entitlements and Authorizations | Container login choices directly affect how permissions and access routes are granted. |
| Recommendation — Align container entitlements with task scope and remove access paths that are broader than operational need. | ||
| CIS Controls v8 | CIS-5 — Account Management | A persistent SSH route introduces another account and credential management surface inside the container. |
| Recommendation — Review container account paths and retire any standing access route that is not required for operations. | ||
Key terms
- Context Scope: Context scope is the set of information an AI agent is allowed to see before it acts. It is an important control because overly broad context can expose sensitive code or data, while overly narrow context can cause bad decisions. Governance should treat context scope as a privileged boundary.
- Standing access path: A standing access path is a persistent way into a system that remains usable without a fresh authorisation event. For non-human identities, it often appears as a service credential, admin channel, or embedded secret that survives long after the original operational need has changed.
- Task-bound Access: Task-bound access is a permission model that grants authority only for a specific, time-limited action and removes it when the task ends. It is a practical control for NHIs because it reduces standing privilege and limits how far a compromised workflow can move.
Deepen your knowledge
NHI governance, agentic AI identity, and machine identity lifecycle are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are building or maturing an IAM programme, it is worth exploring.
Published by the NHIMG editorial team on June 8, 2026.
Updated on October 8, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org