Background
Graphics from an "su'd user" does not work because that other user is not allowed to write (open windows) in your desktop environment. It works if you log out and log in as that user, or if you use some special tool, like steeldriver suggests.
The light-weight solution is using xhost
and gksu
, but there might still be some problems because you [try to] write, where you are not 'supposed to' write.
Using an ssh server and ssh -X
into the same computer is 'overkill' and adds unnecessary overhead, but can be used if you want to run like that once in a while (particularly if you have the ssh server installed already for other purposes). ssh -X
works in a very reliable way with most GUI programs.
xhost and gksu
It is possible to run graphical programs as another user with xhost
and gksu
. It is important to use gksu
to avoid overwriting your configuration files with those of the other user. This can create problems for you to run the same GUI program as your own user, the same problem as if you run GUI programs with sudo
. In other words, use gksu
or gksudo
with GUI programs.
Text after the character #
is a comment and not used.
In newer versions of standard Ubuntu you must install gksu
sudo add-apt repository universe # at least in live and persistent live systems
sudo apt-get update
sudo apt-get install gksu
Prepare with xhost
xhost local:other-user # general
xhost local:sudodus # example, use the actual user ID
Now it should work to use gksu
to run a program as the other user
gksu -w -u other-user gedit file-to-edit # general
pwd > i-am-here # only to show 'where you are'
gksu -w -u sudodus gedit i-am-here # example
I noticed that the current directory of gedit
will be the original user's directory. And the other user should not write there. In other words, it is a good idea to use the full path to the file to edit, or use for example
gksu -w -u sudodus gedit /home/sudodus/file-to-edit # example
When you do a simple text mode su
su - other-user # general
su - sudodus # example
the current directory will be the home directory of the other user.
See Eliah Kagan's answer at this link for more details
askubuntu.com/questions/168815/how-to-get-graphical-display-when-executing-commands-as-another-user ...
Look for Running Graphical Commands Directly as Another User
ssh -X
ssh
(text only) and ssh -X
(also graphics) are intended for log in to another computer, but it can be used locally too, if you have installed an ssh server, for example
sudo apt-get install openssh-server
I can log in like this
$ ssh -X sudodus@127.0.0.1
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:XZBdC58tpt8ud63Z7DfZRX9DYp4xPq6uh0aI07fLlqg.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '127.0.0.1' (ECDSA) to the list of known hosts.
sudodus@127.0.0.1's password:
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-64-generic i686)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
9 paket kan uppdateras.
0 uppdateringar är säkerhetsuppdateringar.
Last login: Tue Feb 14 13:51:52 2017 from 192.168.0.2
sudodus@xenial32 ~ $
Now, if I start for example firefox
, it will work. Some graphical programs might not work, but most programs work this way. See the following links
help.ubuntu.com/14.04/serverguide/openssh-server.html
askubuntu.com/questions/886313/what-is-the-simplest-way-to-have-remote-gui-access ...
xhost
?ssh -X
, but I have not usedxhost
so that would be for you or @steeldriver to elaborate :-)xhost
andgksu
. I added a paragraph about it in my answer.