Skip to main content

X11 doesn't work after sudo to another user

This is kind of old trick but after years of not using X11 at all, I will need to refresh.

Most of the times at my client, linux access is given with my own user name with ability to sudo to a regular service user. On a need of X11 GUI, it's mandatory to add the authorization info of my own user name into the sudo user name so X11 window can be started on top of the sudo user.

But first of all, make sure the X11 forwarding is enabled by adding the following to /etc/ssh/sshd_config

X11Forwarding yes

Before the authorization info is added, the following error may show up in the terminal when trying to bring up X11 window.

X11 proxy: Authorisation not recognised

Here is how to add the authorization.

1. go back to the user who has access to the linux box and get the following info -

>> echo $DISPLAY
this will print out the display variable of the current user

>>xauth list
this will print out the authorization info to connect to the X server of the current user

2. sudo to the service user

>> export DISPLAY=Value_from_step_1

>> xauth add auth_info_from_step_1

3. test use "xclock"

Comments

rajani said…
Thank you so much for the great article. It’s quite informative.
DevOps Training
DevOps Online Training