x forwarding for a sudo session in Linux
X forwarding for a sudo session
What is “xauth”
The xauth program is used to edit and display the authorization information used in connecting to the X server. This program is usually used to extract authorization records from one machine and merge them in on another.
“xauth list”
Authorization entries for each of the specified displays (or all if no displays are named) are printed on the standard output.
“xauth add”
An authorization entry for the indicated display using the given protocol and key data is added to the authorization file. The data is specified as an even-lengthed string of hexadecimal digits, each pair representing one octet. The first digit of each pair gives the most significant 4 bits of the octet, and the second digit of the pair gives the least significant 4 bits. For example, a 32 character hexkey would represent a 128-bit value.
Procedure:
Step 1: Login to your local system to your user account. In this example, “user1”
#user1@local-pc$ ssh -XC server
Step2: Grab the output of “xauth list”
#user1@server1$ xauth list [capture the output]
Step 3: sudo login to the desired account. In this example “user2”
#user1@server1$ sudo su - user2
Step4: Add xauth entries to this session
#user2@server1$ xauth add <paste output from "xauth list">
Step5: Launch the graphics application
#user2@server1$ gedit