Friday, September 27, 2013

How to run GUI applications on Linux with sudo

Linux graphical system configuration tools such as system-config-printer require running desktop environment. I find myself often in need to configure system from remote desktop (via VNC client) with only sudo privileges available to me. Often such systems don't offer GDM access and limit remote desktop access to a selected group of users with sudo privileges only. If we were to launch system-config-printer from shell prompt as a regular user, we would get Query dialog asking to enter root password:
 
$ system-config-printer

To get around this problem, we need to use 'sudo' command in combination with setting DISPLAY environment variable.
First, find out your system hostname:
 
$ hostname
darkstar

Then use sudo:
 
$ sudo DISPLAY=darkstar:1 system-config-printer
Enter your password to run commands as root@darkstar: xxxxx  

You should see Printer configuration dialog pop-up on your screen.


Note that I used 'darkstar:1' as my VNC session is :1 in this example. Your settings might differ.

No comments:

Post a Comment