Skip to content

Instantly share code, notes, and snippets.

@mike-cumulus
Last active October 12, 2023 17:57
Show Gist options
  • Save mike-cumulus/d2b69a41cc9275cf34a908f82ab20999 to your computer and use it in GitHub Desktop.
Save mike-cumulus/d2b69a41cc9275cf34a908f82ab20999 to your computer and use it in GitHub Desktop.
Installing WSL2, Docker, SSH, and Git on Windows 11

Installing WSL2, Docker, SSH, and Git on Windows 11

WSL2

MS Guide: https://docs.microsoft.com/en-us/windows/wsl/install

wsl --install

Follow Up Guide: https://docs.microsoft.com/en-us/windows/wsl/setup/environment

sudo apt update && sudo apt upgrade

Tip: Open Explorer in current WSL dir: explorer.exe

Tip: Open Windows file system from WSL: cd /mnt/c/Users/username

Docker

https://docs.docker.com/desktop/windows/install/

Download installer and run.

Git / SSH

Install SSH Agent for Windows

Use command from an Admin PowerShell Console: Get-Service ssh-agent | Set-Service -StartupType Automatic

Start the agent manually first time: ssh-agent

Generate a new key from PowerShell (non-admin) ssh-keygen -t ed25519 -C "mike@computer"

Add the new key to the agent: ssh-add .\.ssh\id_ed25519

Add public key to bitbucket and github profiles.

Test the SSH connection: ssh -T [email protected]

Install Git for Windows

Download and run Windows installer. Choose the following:

  • Editor: Vim
  • Branch Name: Overide with "main"
  • Git from command line and 3rd party software
  • Use external OpenSSH
  • Use OpenSSL library
  • Line endings: Default (checkout windows style, commit unix style)
  • Terminal: Use MinTTY
  • Git Pull: Default
  • Git Credential Manager
  • Extra options: use defaults
  • No experimental options
git config --global user.name "Mike Rose"
git config --global user.email "[email protected]"

Open a cmd prompt and try to clone a repo.

Git for WSL

Git is installed on WSL2 by default.

https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-git

Maybe someday follow the "Git Credential Manager setup" in the MS link above.

From WSL Console:

Edit .bashrc and add the following. Can use this to edit: notepad.exe ~/.bashrc

#Use SSH key from Windows FS
echo "Starting ssh agent..."
eval "$(ssh-agent -s)"
echo "Adding ssh key: /mnt/c/Users/cumul/.ssh/id_ed25519"
ssh-add - < "/mnt/c/Users/cumul/.ssh/id_ed25519"

VS Code doesn't use .profile, but .profile should execute .bashrc so this should work for terminal and vscode.

Edit .bash_logout and add the following. Can use this to edit: notepad.exe ~/.bash_logout

#added to clean up ssh agents if possible
kill $SSH_AGENT_PID

Close WSL console and open a new one. You should see a message about starting the ssh agent.

Test SSH to github: ssh -T [email protected]

Finish git config:

git config --global user.name "Mike Rose"
git config --global user.email "[email protected]"

Bonus: VSCode

Might as well install vscode at this point. Download and install.

Install Pluggins:

  • Docker
  • Remote - Containers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment