DEV Community

Theodor Heiselberg
Theodor Heiselberg

Posted on • Edited on

Share Git credentials with your container and use ssh access - use dotfiles like a pro!

This is a run down of this article - Link! On how to access your git accounts from within your running devcontainers using SSH.

  1. Add openssh-client to your Dockerfile
RUN apt-get update && \  apt-get install -y --no-install-recommends \  git \  curl \  unzip \  stow \  zsh \  openssh-client \ # <-- ADD && \ # Clean up the apt cache to keep the image size small rm -rf /var/lib/apt/lists/* 
Enter fullscreen mode Exit fullscreen mode
  1. Allow Agent Forwarding
Host s1 HostName stash.stil.dk AddKeysToAgent yes User x151998 UseKeychain yes IdentityFile ~/.ssh/id_rsa.stil ForwardAgent yes # <-- ADD 
Enter fullscreen mode Exit fullscreen mode
  1. Start your devcontainer

How to test the setup

root# echo $SSH_AUTH_SOCK /tmp/vscode-ssh-auth-secret.sock root# ssh-add -l 2048 SHA256:finger sukkerfrit@secret.local (RSA) root# ssh -T git@github.com Hi sukkergris! You've successfully authenticated, but GitHub does not provide shell access. 
Enter fullscreen mode Exit fullscreen mode

Now let's enable the usage of aliases!

  1. Add .ssh to your dotfiles
Host g1 HostName github.com User git ForwardAgent yes PreferredAuthentications publickey 
Enter fullscreen mode Exit fullscreen mode

So, if you like me ara using aliases you can now use git from within your container :)

Vola!

Top comments (0)