Quote:
Originally Posted by milomak
looking to do it from a console (ie within whatever DE).
So I would be looking to setup something where I could the following for instance:
|
That normally won't work as is: when you use su with the minus option, it tells su that you want to discard all the environment variables for the current session, and start a whole new login. Unfortunately, the DISPLAY environment variable is used to tell the X program which X server to use.
One option is to use plain "su" without the minus option, but then any configuration files will probably be written to the home directory of the user who invoked the program, which isn't ideal. Another option, as others have suggested, is to use an appropriate X-aware sudo frontend to run the program. gksu and sux will do a su - and keep just the DISPLAY variable.
You can also do it by working directly from the terminal. First, before you type su, you need to find out what your display environment is:
This will normally return "localhost:0.0", meaning the local machine, first (0-based) display, first (0-based) screen. ("localhost" is implied if omitted, so you may just see ":0.0").
Then run your command as root, setting the DISPLAY variable:
Code:
$ su -
# export DISPLAY=localhost:0.0
# gparted
You can also modify DISPLAY for the regular user account using export. For example, you can run commands on other X servers running on other computers on the network (see the man-page on the xset command for how to set this up). Or you can use /etc/inittab to set up multiple X sessions on different virtual terminals and use the display number to choose which one to use (ctrl+alt+f7/f8/f9 etc to switch between them).
If you are asking this because you are connecting into another computer using ssh and want to run commands as root, but have them display on your local computer, then you can pass the -X option to ssh, which will set up the port-forwarding and handle xset for you, and set DISPLAY - but you will still need to remember to change DISPLAY when you use su.
Hope that helps,
—Robert J Lee