Linux: Using ssh x-forward and su

If you need to open X applications over a ssh session, using a different user than the one you are logging on the linux box, you have to use some tricks.
We are assuming that you have already configured your ssh server to allow x-forwarding.

There was a time where a wrapper called 'sux' was the way to go but now it is not present on newer linux distributions or, if exists, it is not working.
If it will work for you, that's good, you just have to run 'sux - username' and you're there.
If it is not working, you have to use a tool called xauth.

First, check what display number is allocated for your session:
[smocanu@centos6 ~]$ env | grep DIS
DISPLAY=centos6:10.0
Second, check cookie ID and put it into clipboard:
[smocanu@centos6 ~]$ xauth list | grep :10
centos6:10  MIT-MAGIC-COOKIE-1  35cc31782e3241e9e5cccad758h5a99c
Now you can switch your user using sudo/su and setup your authorization entry for this new user, in this case, for root:
[smocanu@centos6 ~]$ sudo su -
[root@centos6 ~]# xauth add centos6:10  MIT-MAGIC-COOKIE-1  35cc31782e3241e9e5cccad758h5a99c
[root@centos6 ~]# xauth list
centos6:10  MIT-MAGIC-COOKIE-1  35cc31782e3241e9e5cccad758h5a99c
Now you should be able to export the X application.


Comments

Popular posts from this blog

JunOS - mount USB stick

SSH: Generating and using SSH keys

Linux: Versioning the /etc/ configurations using 'etckeeper'