3

Using Ubuntu 14.04 with Unity. I log in with my usual user (admin) in graphic environment. Once logged, I'd like to run GUI-commands like if I were another user (normal), to test a client-server application. I need several users (one for server and another for each client), because each one needs an own $HOME environment. In the future, they are supposed to be installed in separate machines.

So, I open a terminal and I do:

su - user 

When I run any GUI command (such as 'xterm'), it tells the usual

No protocol specified
Cannot open display:

I read several ways to solve this using xauth, xhost, etc., but the one that worked for my purposes was:

admin# sudo cp ~/.Xauthority ~user/. 
admin# sudo chown user ~user/.Xauthority
admin# su - user

user$ export XAUTHORITY=~/.Xauthority

Now I can run any GUI command, such as xterm.

However this solution, only works within same GUI session. Once you reboot computer, .Xauthority file changed, and this solution is no longer valid, unless I copy .Xauthority again, which is tedious and involves sudo commands to copy.

So, is there a way, to make it persistent within .bashrc or some other way? I mean, once I open a terminal from GUI and log in using su - <user>, would be capable to run commands that require GUI without have to do all previous stuff.

Sorry for English.

  • did you try gksu? it has ` -l` for login and -u to specify a user. – TmTron Jun 14 '16 at 8:47
  • HI @TmTron. Yes, but as far as know, it opens a dialog to run a command, and I don't want that. I need a terminal to compile and do some other stuff, that is able to run GUI commands (because client runs a GUI app). – Albert Jun 14 '16 at 9:01
0

You can use a local network login (ssh) instead of su. The option -X will enable forwarding of the X connection:

ssh -X username@localhost

For this to work, you must have a secure shell server (sshd) running on the host (apt install openssh-server). It will prompt you for a password and drop you in a shell, just like su - username, but with forwarding of the X Window connection. It works for remote hosts, but also locally.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.