Just created a user from the Ubuntu user management window on my laptop. Confirmed the /home/newuser
directory was created.
So I open a terminal window, su
into the new user account and that works OK. When I try opening pluma, gedit, firefox or any X application, I get:
Error: cannot open display: :0.0
Other user accounts on the same laptop are able to open these same applications via command line. Just not this newly created account (from the User Management gui using defaults).
What gives?
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
andgksu
, 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
andgksu
. It is important to usegksu
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 withsudo
. In other words, usegksu
orgksudo
with GUI programs.Text after the character
#
is a comment and not used.In newer versions of standard Ubuntu you must install
gksu
Prepare with
xhost
Now it should work to use
gksu
to run a program as the other userI 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 exampleWhen you do a simple text mode
su
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) andssh -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 exampleI can log in like this
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 linkshelp.ubuntu.com/14.04/serverguide/openssh-server.html
askubuntu.com/questions/886313/what-is-the-simplest-way-to-have-remote-gui-access ...