sudo for X Programs

By default (at least on my machine), it wasn’t possible to open X applications using sudo. For example sudoing xclock resulted in the following error:

$ sudo xclock
No protocol specified
Error: Can't open display: :0.0

The same error appeared even when I executed xclock after running sudo su.

Apperantly, by default the X server doesn’t allow anyone else besides you to open windows on the display. While it’s generally a good thing, it’s annoying if you’re trying to preform some GUI stuff as root. You can use the xauth utility to grant permissions to other users. For example:

$ xhost local:root
non-network local connections being added to access control list

Allows root user connecting from the local machine (like sudo) to access the X display for your user. You can see the current access list by simply typing xhost.

2 thoughts on “sudo for X Programs

  1. Manjeet Dahiya

    Hello Guy! I have been following your blog for a while.

    Quite liked the source-code posting style. Which plugin do you use for the same?

    I found Github-Gist cool too! One can just push to Github without worrying about updating the blog post.

  2. Guy Post author

    Hi,

    I’m using wp-syntax. Github-Gist looks very nice, I didn’t hear about it before. There are two things which trouble me with it:
    1. The embedding code is javascript. This means that if I search my blog for some code, it won’t find it in the snippets.
    2. What happens if somebody else pushes changes to my gist? Will it update my post too?

Leave a Reply

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