wsl check if we are on a remote ssh session

The following checks may still work in WSL:

  • If one of the variables SSH_CLIENT or SSH_TTY is defined
  • If the login shell's parent process name is sshd

If the ssh server is running inside windows and not wsl itself, from wsl you will need to escape into cmd and check.

This is what I came up with:

echo $(cmd.exe /c 'echo %SSH_CLIENT%' 2>/dev/null | sed $'s/\r//' | grep ' 22$')