This only took two days of fighting with every AI Coder in the world. Finally, ChatGPT came up with the answer for using a SSH key for Github with a Mac computer running colima and using devcontainer in vs code.

GitHub SSH Key Setup for Devcontainer (Colima-Compatible)

To enable git push and other SSH-based GitHub operations inside the devcontainer, one must mount a GitHub-specific SSH key directly into the container. This avoids issues with SSH agent forwarding under Colima, which runs Docker inside a VM and cannot expose host sockets.

Procedure

  • Generate a GitHub-only SSH key:

    ssh-keygen -t ed25519 -C "github-devcontainer" -f ~/.ssh/id_github
    
  • Add the public key (~/.ssh/id_github.pub) to your GitHub account at GitHub SSH Key Settings

  • **Update devcontainer.json

Mount the key ssh directly in devcontainer.json:

"mounts": [
  ...
  "source=/Users/murwell/.ssh/id_github,target=/root/.ssh/id_rsa,type=bind,consistency=cached",
  "source=/Users/murwell/.ssh/id_github.pub,target=/root/.ssh/id_rsa.pub,type=bind,consistency=cached"
]

Add to postCreateCommand to fix permissions:

"postCreateCommand": "chmod 600 /root/.ssh/id_rsa && chmod 644 /root/.ssh/id_rsa.pub"

Notes

  • The SSH user for GitHub is always:

    git@github.com
    
  • GitHub identifies you by your SSH key, not the username.
  • This setup avoids unreliable SSH_AUTH_SOCK mounting under Colima/macOS.
  • The mounted key will persist across container rebuilds.
  • You can test it inside the container:

    ssh -T git@github.com
    

Visit Emlekezik.com