Solved su in xterm - Running Graphical Applications

Let's say I'm running xterm, and I su; I'm then root, and I want to run a qt4 application in my X session I'm running as another user.

Can I do that? How would I do that?

I can't imagine I'm the first person who wants to do that, so I figure there must be a way...
 
Provided that you can already start X applications from within that xterm there's nothing more you have to do. Just be sure to run su without any parameters such as -, this will ensure that you gain root privileges while maintaining your current environment (which includes the DISPLAY setting which will point the system to your X environment).
 
Also it is possible to use x11/xhost
NBT49e8.gif


To enable "access control" again, use % xhost -
 
Provided that you can already start X applications from within that xterm there's nothing more you have to do. Just be sure to run su without any parameters such as -, this will ensure that you gain root privileges while maintaining your current environment (which includes the DISPLAY setting which will point the system to your X environment).

Hmmm... That's not quite how it works for me... : [

Also it is possible to use x11/xhost
NBT49e8.gif


To enable "access control" again, use % xhost -

Now that is awesome!
 
You can also do it via sudo(8) if you add the following to your sudoers(5) file:
Code:
Defaults  env_keep += "DISPLAY HOME"
Then you just need to use sudo whateverXappYouWant to run the program.

We use this setup to allow for running virt-manager GUI on remote KVM-based servers via OpenSSH' X11 forwarding. :) We limit this env_keep to only the virt-manager command for a bit of extra "security".
 
What?

WTH... it works now : \

su and then running whatever works now, but it wasn't working yesterday... Maybe because I rebooted or something, or maybe because I added the -, but I'm not doing that these days, so I think it's just the reboot... either that, or I'm an idiot... probably the former... : P
 
To run apps from another user, % xhost + should be used,
for example ( % xhost - is set by default):
uWiHzov.gif


If you want to grant access to specific user, execute
% xhost '+si:localuser:[i]specificusername[/i]'

Also it is possible to use ssh to launch GUI apps as specific user,
but sshd should be enabled and "X11Forwarding" should be set to "yes"
in /etc/ssh/sshd_config (set by default), to launch firefox, for example, as specific user, use
% ssh -Y [i]specificusername[/i]@0 firefox
To disable password request every time you launch this, add your ~/.ssh/id_rsa.pub
to "specific user's" $HOME/.ssh/authorized_keys file.
 
Last edited by a moderator:
What?

WTH... it works now : \

su and then running whatever works now, but it wasn't working yesterday... Maybe because I rebooted or something, or maybe because I added the -, but I'm not doing that these days, so I think it's just the reboot... either that, or I'm an idiot... probably the former... : P

su - username tells it to simulate a login as username, which means you get the environment, shell configuration, etc as if you did a full login from the console.

su username tells it to switch the userid/username to username but doesn't touch anything else. You keep your current environment, shell, etc.

Very big difference in how the two work. :)
 
Back
Top