Skip to content

macOS SSH agent forwarding not working any longer #7204

Open

Description

@outsinre

Description

SSH agent forwarding described at https://docs.docker.com/desktop/networking/#ssh-agent-forwarding does not work any longer after recent Docker Desktop upgrade and macOS upgrade. It worked a few months ago.

Reproduce

  1. Start Docker Desktop.

  2. SSH agent on host.

    ~ $ ssh-add -l
    384 SHA256:a2TyZj/tyhwUrs6XYhg//+Zwnpvwp9yttted4OgmWtg ...
    4096 SHA256:x2gO9GTWyTkJLudIwcFwHXYez0BFktfSc9FZ/jGqPU ...
  3. Launch a new container.

    ~ $ docker run --rm -it -u root \
    --mount "type=bind,src=/run/host-services/ssh-auth.sock,target=/run/host-services/ssh-auth.sock" \
    -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" \
    ubuntu:latest bash
    
    root@c7783e0b7cd5:/# apt-get update && apt-get install -y ssh
  4. SSH agent in the container. No SSH keys found!

    root@c7783e0b7cd5:/# ssh-add -l
    The agent has no identities.

Expected behavior

SSH agent in the container should see the SSH keys in the forwarded SSH agent.

docker version

Client:
 Cloud integration: v1.0.35+desktop.10
 Version:           25.0.3
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        4debf41
 Built:             Tue Feb  6 21:13:26 2024
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.27.2 (137060)
 Engine:
  Version:          25.0.3
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       f417435
  Built:            Tue Feb  6 21:14:22 2024
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client:
 Version:    25.0.3
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1-desktop.4
    Path:     /Users/zachary/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.5-desktop.1
    Path:     /Users/zachary/.docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container. (Docker Inc.)
    Version:  0.0.24
    Path:     /Users/zachary/.docker/cli-plugins/docker-debug
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /Users/zachary/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.21
    Path:     /Users/zachary/.docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     /Users/zachary/.docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.0.0
    Path:     /Users/zachary/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/zachary/.docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.4.1
    Path:     /Users/zachary/.docker/cli-plugins/docker-scout
WARNING: Plugin "/Users/zachary/.docker/cli-plugins/docker-scan" is not valid: failed to fetch metadata: fork/exec /Users/zachary/.docker/cli-plugins/docker-scan: no such file or directory

Server:
 Containers: 2
  Running: 0
  Paused: 0
  Stopped: 2
 Images: 58
 Server Version: 25.0.3
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.6.12-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 10
 Total Memory: 7.657GiB
 Name: docker-desktop
 ID: c3700971-3280-4ddf-a6b2-ed3956797d34
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

Diagnostics ID

FD6CD52B-6D96-4731-9597-7A67E1E7F302/20240228141331

Additional Info

No response

Activity

  1. outsinre commented on Feb 28, 2024

    @outsinre
    Author

    After some search, found a similar issue: #6541 (Docker version 4.13.0) with a workaround to bypass this bug: start Docker Desktop (open -a Docker) from terminal instead of from launchpad. However, this seems to have performance issue. Docker engine does not respond to commands instantly.

    Using this way, only root user can access to the forwarded agent. For non-root user, we have to update the permission as follows. See #4242 and #5303.

    ~ $ ll /run/host-services/ssh-auth.sock
    srwxr-xr-x 1 root root 0 Feb 28 14:39 /run/host-services/ssh-auth.sock
    
    ~ $ sudo chmod a+w /run/host-services/ssh-auth.sock

    Alternatively, setting the "file sharing" from "VirtioFS" to "gRPC FUSE". See https://stackoverflow.com/q/76343112.

  2. self-assigned this
    on Feb 29, 2024
  3. removed their assignment
    on Apr 22, 2024
  4. alx75 commented on Nov 4, 2024

    @alx75

    I had the same issue and open -a Docker does the trick for root user. Would it make sense to start ssh-agent only if SSH_AUTH_SOCK is not already set to avoid this issue ?

    Docker desktop version: Docker Desktop 4.35.1 (173168)

  5. bedrich-schindler commented on May 29, 2025

    @bedrich-schindler

    I have exactly the same issue, SSH agent forwarding only work when Docker is run using open -a Docker.

    docker info:

    Client:
     Version:    28.1.1
     Context:    desktop-linux
     Debug Mode: false
     Plugins:
      ai: Docker AI Agent - Ask Gordon (Docker Inc.)
        Version:  v1.1.7
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-ai
      buildx: Docker Buildx (Docker Inc.)
        Version:  v0.23.0-desktop.1
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-buildx
      cloud: Docker Cloud (Docker Inc.)
        Version:  v0.3.0
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-cloud
      compose: Docker Compose (Docker Inc.)
        Version:  v2.35.1-desktop.1
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-compose
      debug: Get a shell into any image or container (Docker Inc.)
        Version:  0.0.38
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-debug
      desktop: Docker Desktop commands (Docker Inc.)
        Version:  v0.1.8
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-desktop
      dev: Docker Dev Environments (Docker Inc.)
        Version:  v0.1.2
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-dev
      extension: Manages Docker extensions (Docker Inc.)
        Version:  v0.2.27
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-extension
      init: Creates Docker-related starter files for your project (Docker Inc.)
        Version:  v1.4.0
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-init
      mcp: Docker MCP Plugin (Docker Inc.)
        Version:  dev
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-mcp
      model: Docker Model Runner (Docker Inc.)
        Version:  v0.1.11
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-model
      sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
        Version:  0.6.0
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-sbom
      scout: Docker Scout (Docker Inc.)
        Version:  v1.17.1
        Path:     /Users/bedrich.schindler/.docker/cli-plugins/docker-scout
    
    Server:
     Containers: 1
      Running: 0
      Paused: 0
      Stopped: 1
     Images: 2
     Server Version: 28.1.1
     Storage Driver: overlay2
      Backing Filesystem: extfs
      Supports d_type: true
      Using metacopy: false
      Native Overlay Diff: true
      userxattr: false
     Logging Driver: json-file
     Cgroup Driver: cgroupfs
     Cgroup Version: 2
     Plugins:
      Volume: local
      Network: bridge host ipvlan macvlan null overlay
      Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
     CDI spec directories:
      /etc/cdi
      /var/run/cdi
     Swarm: inactive
     Runtimes: io.containerd.runc.v2 runc
     Default Runtime: runc
     Init Binary: docker-init
     containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
     runc version: v1.2.5-0-g59923ef
     init version: de40ad0
     Security Options:
      seccomp
       Profile: unconfined
      cgroupns
     Kernel Version: 6.10.14-linuxkit
     Operating System: Docker Desktop
     OSType: linux
     Architecture: aarch64
     CPUs: 12
     Total Memory: 7.653GiB
     Name: docker-desktop
     ID: 5e4baa73-ed4f-41e2-b31b-80b8f269acbf
     Docker Root Dir: /var/lib/docker
     Debug Mode: false
     HTTP Proxy: http.docker.internal:3128
     HTTPS Proxy: http.docker.internal:3128
     No Proxy: hubproxy.docker.internal
     Labels:
      com.docker.desktop.address=unix:///Users/bedrich.schindler/Library/Containers/com.docker.docker/Data/docker-cli.sock
     Experimental: false
     Insecure Registries:
      hubproxy.docker.internal:5555
      ::1/128
      127.0.0.0/8
     Live Restore Enabled: false
    
    WARNING: DOCKER_INSECURE_NO_IPTABLES_RAW is set
    WARNING: daemon is not using the default seccomp profile
    

    docker version:

    Client:
     Version:           28.1.1
     API version:       1.49
     Go version:        go1.23.8
     Git commit:        4eba377
     Built:             Fri Apr 18 09:49:45 2025
     OS/Arch:           darwin/arm64
     Context:           desktop-linux
    
    Server: Docker Desktop 4.41.2 (191736)
     Engine:
      Version:          28.1.1
      API version:      1.49 (minimum version 1.24)
      Go version:       go1.23.8
      Git commit:       01f442b
      Built:            Fri Apr 18 09:52:08 2025
      OS/Arch:          linux/arm64
      Experimental:     false
     containerd:
      Version:          1.7.27
      GitCommit:        05044ec0a9a75232cad458027ca83437aae3f4da
     runc:
      Version:          1.2.5
      GitCommit:        v1.2.5-0-g59923ef
     docker-init:
      Version:          0.19.0
      GitCommit:        de40ad0
    

    System info:

    Apple MacBook Pro M2 MAX 32 GB
    MacOS 15.4.1
    
  6. bedrich-schindler commented on Jun 2, 2025

    @bedrich-schindler

    Solution

    I've found the solution for those who use Oh My Zsh or similar shell framework! We had been struggling with SSH agent forwarding as it had been working for others, including those who use Oh My Zsh.

    The problem is that Oh My Zsh with ssh-agent plugin explicitly blocks SSH agent forwarding if it is not enabled in its configuration. So, if you use ssh-agent plugin, you must enable SSH agent forwarding according to the documentation: https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/ssh-agent/README.md#settings

    I think that the reason why it works with open -a Docker is that it uses different SSH agent started by Oh My Zsh shell.

  7. rocky-foreflight commented on Jul 21, 2025

    @rocky-foreflight

    This is insane. I can't believe I found this issue because I felt like I was being gaslit. "Why did this work yesterday?" etc. etc.

    Turns out I'm a weirdo and open apps from my Terminal often with open -a <app> and that's how I happened to open Docker the first few times I tried SSH agent forwarding. Now, I happened to open Docker through Spotlight and it doesn't work.

    For example, with my user specifics redacted:

    $ docker compose run --rm <my-dev-container>
    647eb8a5a725:/workspace# ssh-add -L
    The agent has no identities.
    647eb8a5a725:/workspace# 
    exit
    
    $ # Quit Docker Desktop, originally launched via Spotlight.
    $ open -a Docker      
    $ docker compose run --rm <my-dev-container>
    29e398884763:/workspace# ssh-add -L
    ssh-ed25519 [...]

    FWIW, my SSH_AUTH_SOCK is non-standard. But using a GPG agent is not that non-standard...

    $ env | grep SSH
    SSH_AUTH_SOCK=/Users/rocky/.gnupg/S.gpg-agent.ssh

    Versions:

    Details
    $ sw_vers
    ProductName:		macOS
    ProductVersion:		15.3.1
    BuildVersion:		24D70
    $ docker version        
    Client:
     Version:           28.3.2
     API version:       1.51
     Go version:        go1.24.5
     Git commit:        578ccf6
     Built:             Wed Jul  9 16:12:57 2025
     OS/Arch:           darwin/arm64
     Context:           desktop-linux
    
    Server: Docker Desktop 4.43.2 (199162)
     Engine:
      Version:          28.3.2
      API version:      1.51 (minimum version 1.24)
      Go version:       go1.24.5
      Git commit:       e77ff99
      Built:            Wed Jul  9 16:13:56 2025
      OS/Arch:          linux/arm64
      Experimental:     false
     containerd:
      Version:          1.7.27
      GitCommit:        05044ec0a9a75232cad458027ca83437aae3f4da
     runc:
      Version:          1.2.5
      GitCommit:        v1.2.5-0-g59923ef
     docker-init:
      Version:          0.19.0
      GitCommit:        de40ad0
    $ docker compose version
    Docker Compose version v2.38.2-desktop.1
  8. rocky-foreflight commented on Jul 22, 2025

    @rocky-foreflight

    Looks related to #4242.

    One solution, respect the user's IdentityAgent stanza in their ~/.ssh/config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions