Wednesday, June 20, 2018

command line - Log in as other user having GUI capability

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 - , would be capable to run commands that require GUI without have to do all previous stuff.




Sorry for English.

No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...