Skip to main content

Windows Terminal SSH connection profiles

· 2 min read
Stephan Hochdörfer

Windows Terminal is one of my favorite and most used tools after migrating to Windows and WSL2 last year. I use if to access all my WSL2 instances, Powershell and I keep track of my SSH connections.

Adding an SSH connection to the list of profiles can be done by creating a new profile and configuring the “commandline” setting as follows:

"commandline": "wsl.exe /usr/bin/ssh myuser@mydomain"

Sadly, this did not work for me because of my Yubikey and GPG4Win setup. During the login in my Ubuntu WSL2 instance, I need to execute the following commands before Linux is able to access the GPG socket from Windows exposing the Yubikey device:

$HOME/.local/bin/gpg-agent-relay start
export SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh

Since I do not want to execute those 2 commands manually on each login, I added those to my user’s .bashrc file. However, when running a Linux command via wsl.exe, the .bashrc file is not executed. The fix I came up with, is creating a separate bash script that will run the commands above before running the SSH command:


$HOME/.local/bin/gpg-agent-relay start
export SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh

ssh $1

Now I can call the script in the “commandline” setting of my Windows Terminal profile:

"commandline": "wsl.exe /home/myuser/bin/ myuser@mydomain"