{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreid2kynz2nsir442rryr747zce2vgdscpxytimuiumugsmu4sif2ta",
"uri": "at://did:plc:25rdn5elo5izoxrmtis34zuk/app.bsky.feed.post/3mp3x27p45422"
},
"coverImage": {
"$type": "blob",
"ref": {
"$link": "bafkreidgwbhlp5f4zeflohoouzfrixtdqeprc5vzdckaawyfpgbjkxee3i"
},
"mimeType": "image/webp",
"size": 60116
},
"path": "/sukkergris/share-sshconfig-with-your-devcontainer-22i9",
"publishedAt": "2026-06-25T07:34:42.000Z",
"site": "https://dev.to",
"tags": [
"macos",
"vscode",
"devcontainer",
"ssh"
],
"textContent": "## How to share your ~/.ssh/config with devcontainers\n\nThe purpose is to enable using git with your provider directly from the devcontainer.\n\nThe problem is when running on mac-OS you typically add `UseKeychain yes` to your config file. Which is a mac specific setting killing your ssh agent.\n\n**MacOS - first**\n\nYour `~/.ssh` folder probably looks something like this:\n\n\n\n ❯ tree\n .\n ├── config\n ├── hetzner_id_ed25519\n ├── hetzner_id_ed25519.pub\n ├── known_hosts\n ├── known_hosts.old\n ├── README.md\n ├── sukkerfrit.github\n ├── sukkerfrit.github.pub\n └── test.sh\n\n\nAnd the content of your `config` something like this:\n\n\n\n Host tahh\n HostName github.com\n User git\n AddKeysToAgent yes\n IdentityFile ~/.ssh/sukkerfrit.github\n IdentitiesOnly yes\n ForwardAgent yes\n\n Host hetzner-ktk-test\n HostName xx.xx.xx.xx\n User root\n AddKeysToAgent yes\n UseKeychain yes\n IdentityFile ~/.ssh/hetzner_id_ed25519\n\n\n**UseKeychain**\nIs a mac-OS specific SSH setting. We use it to save and fetch the SSH-key passphrase automatically.\n\nBUT it doesn't work on Linux and will actually course an exception on load rendering using eg. git directly from your devcontainer impossible.\n\nThis image is just working on `root` which i normally never do. I use to create a `container-user` in my container - I guess I was just lazy today.\n\nThis is way I share my `~/.ssh/config` with devcontainers.\n\n## 1. Add host's ~/.ssh to docker as mount\n\nMy 'trick' is to just mount my host's .ssh folder as read only - but to eg. **/root/.sshtemplate**.\n\nThen you don't end up editing your host's config.\n\n`devcontainer.json`\n\n\n\n {\n \"name\": \"some-funkey-name\",\n \"dockerComposeFile\": \"docker-compose.yml\",\n \"service\": \"development\",\n \"workspaceFolder\": \"/xyz\",\n \"postCreateCommand\": \"./.devcontainer/post-container-install.sh\",\n \"mounts\": [\n \"source=${localEnv:HOME}/.ssh,target=/root/.sshtemplate,type=bind,readonly,consistency=cached\"\n ],\n\n\nChange the target if you work on a different user.\n\n## 2. Copy from .sshtemplate -> .ssh\n\n`copy-ssh-files.sh`\n\n\n\n #!/usr/bin/env bash\n set -u\n\n if [ -d /root/.sshtemplate ]; then\n cp -rf /root/.sshtemplate/. ~/.ssh/\n chmod 700 ~/.ssh\n chmod 600 ~/.ssh/* 2>/dev/null || true\n fi\n\n\n## 3. Remove lines with `UseKeychain`\n\n`remove-usekeychain-lines.sh`\n\n\n\n #!/usr/bin/env bash\n set -u\n\n # Remove UseKeychain (case-insensitive) from a config file if it exists\n if [ -f \"$1\" ]; then\n sed -i '/UseKeychain/I d' \"$1\"\n echo \"UseKeychain removed from $1.\"\n fi\n\n\n## 4. Create post install file\n\n`post-container-install.sh`\n\n\n\n #!/usr/bin/env bash\n ...\n \"$SCRIPTS_DIR/copy-ssh-files.sh\"\n \"$SCRIPTS_DIR/remove-usekeychain-lines.sh\" ~/.ssh/config\n\n\nEnjoy!",
"title": "Share .ssh/config with your devcontainer"
}