Tuesday, March 8, 2016

Quick Tip: Linux How to Enable X11 Forwarding in a SSH sudo Session


Recently I had to install some Oracle products for a customer. I provided my list of pre-requisites to them as per Oracle docs. We usually create a user called 'oracle' as Linux software owner but due to security reasons we didn't had access to 'oracle' user directly. Instead everyone have their own ID (For example zbaig) and then you run the sudo command to switch user.


  • You need X server running on your desktop. I use Xming because it is lightweight. 
  • Make sure you have X11 Forwarding enabled in SSH utility like PuTTY or Secure Shell
  • Make sure X11 is enabled on the Linux server by root 


The X11 was working when you log in directly in SSH (like with zbaig) but it wasn't working when I issue sudo command as follows

[zbaig@server1] sudo -i -u oracle

[sudo] password for zbaig:
[zbaig@server1] xclock

Error: Can't open display:


You need to enable X11 for the other user as well, run the following commands

[zbaig@server1] /home/home01/zbaig $ xauth list
server2/unix:10  MIT-MAGIC-COOKIE-1  d3ce0c405b6ed8991916e47f8d532aef
server1/unix:10  MIT-MAGIC-COOKIE-1  a7c707e46943228264045845244d5c3c

[zbaig@server1] /home/home01/zbaig $ sudo -i -u oracle
[sudo] password for zbaig:

In the following "xauth add" command paste the output of above command of 'server1' (you might see other COOKIE list as well, but use the server you are working on)

[oracle@server1] /usr/home/oracle $ xauth add server1/unix:10  MIT-MAGIC-COOKIE-1  a7c707e46943228264045845244d5c3c
xauth:  creating new authority file /usr/appl/nes/home/oracleuser/.Xauthority

[oracle@server1] /usr/home/oracle $ xclock

All should be good.

Hope you find this useful,


No comments:

Post a Comment