X Forwarding Sudo SSH Session


Many environments make use of sudo to delegate access to administrative or application user accounts. This can make ssh X forwarding tricky because your environment changes as you sudo to another user. This is a workaround that will allow you to continue your ssh X forwarding session while running sudo as another user.

How to SSH X Forward Sudo

First you will need a working X11 environment on your local system. There are a number of different options available depending on your OS.

Once you have your local X11 environment working and tested you’re ready to proceed x forwarding sudo.

[email protected]$ ssh -XC server
 
[email protected]$ xauth list
[output]
 
[email protected]$ sudo su - otheruser
 
[email protected]$ xauth add [paste output from "xauth list"]
 
[email protected]$ xterm (or other X application)

For more information please refer to the xauth, sudo and ssh man pages.

For x11 on a non-linux OS:

Xming for windows http://sourceforge.net/projects/xming/
Xquartz for OSX http://xquartz.macosforge.org/landing/

One Response to “X Forwarding Sudo SSH Session”

  1. VIKAS Says:

    Just to add my inputs too. I have used xshell (or xmanager) for years without any issues on Windows. It is an awesome piece of software.

    Regards,
    Vikas

    [Reply]

Join the Conversation