XAuth Port Forwarding For Linux GUI

Here is an example of something I don’t have to worry about everyday, so it’s definitely worth writing down for my own reference.

Sometimes having GUI access to a linux box become beneficial to perform tasks. If X11 libraries are installed on the host, you can use the following command to port GUI.

Obtain XAuth cookies

[ec2-user@TestOraHost ~]$ xauth list $DISPLAY
TestOraHost/unix:10  MIT-MAGIC-COOKIE-1  53677406f4a2179e1f08e330d44c79ba

Connect as desired user. In my case, I’m switching to ‘oracle’ OS user

[ec2-user@TestOraHost ~]$ sudo su - oracle
Last login: Tue May  7 02:31:19 UTC 2019 on pts/2

Add the XAuth cookies to the desired user.

[oracle@TestOraHost ~]$ xauth add TestOraHost/unix:10  MIT-MAGIC-COOKIE-1  53677406f4a2179e1f08e330d44c79b

Set linux DISPLAY variable by using the port identified above.

[oracle@TestOraHost ~]$ export DISPLAY=localhost:10.0

Test the GUI by running xclock

[oracle@TestOraHost ~]$ xclock