Skip to content

Instantly share code, notes, and snippets.

@filviu
Created October 29, 2021 09:38
Show Gist options
  • Save filviu/ff287e2e6fd0662fa6648bf457235184 to your computer and use it in GitHub Desktop.
Save filviu/ff287e2e6fd0662fa6648bf457235184 to your computer and use it in GitHub Desktop.
SSH_AUTH_SOCK with remote desktop and vscode
# make sure your .bashrc actually loads a .bashrc.local
if [ "$TERM_PROGRAM" != "vscode" ]; then
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
fi

SSH Forwarding with remote desktop and vscode support

Motivation: I have remote workstation that I don't want to leave ssh keys laying around. All my ssh keys are inside keepass.

Sollution: use ssh agent forwading (basically forwading the keepass2 kee-agent via ssh) to the remote machine

Problem: Using e.g. konsole over remote desktop doesn't work.

Sollution: make the SSH_AUTH_SOCK always available via symlink at a preffered location

Problem: vscode also symlinks SSH_AUTH_SOCK to it's preffered location and my code doesn't touch the SSH_AUTH_SOCK if it's already a symlink

Complete Sollution below :)

Problem left:

If you open multiple ssh connections and you close the last one this stops working. I can live with it but I'm open to suggestions on how to fix that.

Based on https://superuser.com/questions/180148/how-do-you-get-screen-to-automatically-connect-to-the-current-ssh-agent-when-re

#!/bin/bash
# Place this under ~/.ssh and make it executable
if [ "$TERM_PROGRAM" == "vscode" ]; then
ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
else
if [ -S "$SSH_AUTH_SOCK" ] && [ ! -h "$SSH_AUTH_SOCK" ]; then
ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment