Make X11 work through sudo su –

I’ve got a server at work that I need to SSH into as a different user, then do an “sudo su -” to become root, and then run a program with X11 forwarding.

I was getting this error:

PuTTY X11 proxy: MIT-MAGIC-COOKIE-1 data did not matchWarning: This program is an suid-root program or is being run by the root user.
The full text of the error or warning message cannot be safely formatted
in this environment. You may get a more descriptive message by running the
program as a non-root user or by removing the suid bit on the executable.
xterm Xt error: Can't open display: %s
root@myserver:~#

Some googling lead me to this blog post which didn’t work for me, but put me on the right path.

Here’s the line I ended up using

su - non_root_user_name -c "xauth list"  | xargs -n 3 xauth add

If you need to use this frequently you could add an alias to you /root/.bashrc file

alias xwork='su - non_root_user_name -c "xauth list"  | xargs -n 3 xauth add'

That way you can just run xwork when you need X11 working.

This entry was posted in Computers and tagged , , , , , . Bookmark the permalink.

One Response to Make X11 work through sudo su –

  1. Nick R says:

    Just because im even lazier…

    alias xwork=’xauth list | sudo xargs -n 3 xauth add’

Leave a Reply

Your email address will not be published. Required fields are marked *