Skip to content

Instantly share code, notes, and snippets.

@gwarf
Last active March 27, 2024 17:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gwarf/5268c3c44bc14a96d1a2ef82093851be to your computer and use it in GitHub Desktop.
Save gwarf/5268c3c44bc14a96d1a2ef82093851be to your computer and use it in GitHub Desktop.
Using ssh forwarding (Agent and X11) on MacOS X

SSH Forwarding on MacOS X

Forwarding SSH agent

Configure ~/.ssh/config

# Allow Agent forwarding for a specific host (by security)
Host remotehost
  ForwardAgent yes
# List existing SSH key in the agent
ssh-add -L
# Add required SSH Key
ssh-add
[user@localmac ~]: ssh user@remotehost
[user@localmac ~]: echo $SSH_AUTH_SOCK
/tmp/ssh-2JfYkZ5O6p/agent.5587
[user@remotehost ~]: ssh user@thirdhost
[user@thirdhost ~]

Using X11 Forwarding with SSH on a MacOS X

Displaying a remote GUI application on the local Mac

brew cask install xquartz

Once xquartz is launched, if you launch a new terminal (such as iTerm) instance DISPLAY should be set in the environment.

[user@localmac ~]: echo $DISPLAY
/private/tmp/com.apple.launchd.drNHsFjcaS/org.macosforge.xquartz:0
[user@localmac ~]: ssh -X user@remoteserver
[user@remoteserver ~]: virt-manager

Configure ~/.ssh/config

# Allow Agent forwarding for a specific host (by security)
Host remotehost
  ForwardAgent yes
  ForwardX11 yes
[user@localmac ~]: ssh user@remoteserver
[user@remoteserver ~]: echo $DISPLAY
localhost:10.0
[user@remoteserver ~]: virt-manager

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment