About Linux FAQ

Browse More FAQs:

Advertisements

How do I run X windows program as normal user?

Posted by Vivek Gite [Last updated: August 28, 2006]

Microsoft windows XP has runas command which allows a user to run specific tools and programs with different permissions than the user's current logon provides. Linux and other UNIX like operating system provides the su or sudo command for same purpose. However, su/sudo command is not so useful when it comes to X program. For example when you logged in as a normal user, you need to run an X window application as root. If I run application as follows:

$ su -
Password
# xeyes

It will bump you back with an error:
(program:15082): Gtk-WARNING **: cannot open display:
OR
** WARNING ** cannot open display

However both KDE and Gnome come with tools to deal with this problem.

Method # 1:
If you are using KDE then use following command at shell prompt:
kdesu command-name

$ kdesu xeyes

Method # 2:
If you are using Gnome then use following command at shell prompt:

$ gksuexec

Or use GUI itself, click on Applications > System tools > Select Run as different user
Method # 3:
Create runas alias as follows:

$ alias runas='su -c $@'

Add above alias to your bash startup script

$ echo "alias runas='su -c $@'" >> .bash_profile

You can now use alias as follows to start any x program

$ runas program-name
$ runas xeyes

Method # 4: The old way
The problem is with two environment variable DISPLAY and XAUTHORITY. You need to setup them correctly to run X windows program as a root user while logged in as a normal user. So how do you fix this problem? Simply set these two variables to point to current logged in users environment variable. Let us assume you are currently login as vivek user.

Step # 1 Become super-use

vivek@debian:~$ su -
debian:~#

Step # 2 Setup variables

# export DISPLAY=0:0
# export XAUTHORITY=/home/vivek/.Xauthority

Step # 3 Execute X program as a root user

# xeyes

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.