0

Visiting the old topic of running X applications as another user under Linux, as the solution had always been "to use gksu" to me, but today, when I need it and tried it, it doesn't work.

Following What Is gksu And Why Would You Use It, I tried,

gksu -u otherusername xterm

After passing the dialog that asks for the password, I got:

$ gksu -u otherusername xterm
xterm: Xt error: Can't open display: :2

I.e., it doesn't work for me. So,

How to run X applications as another user under Linux? Thx.

PS, this is Ubuntu 17.04:

$ lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 17.04
Release:        17.04
Codename:       zesty
xpt
  • 9,385
  • 44
  • 120
  • 178

3 Answers3

2

Ubuntu 17, right? Are you sure you are actually running Xorg, and not Wayland? (i.e. does ps auxfww actually shows a program called X running?)

If you are running Wayland-- which you would be by default: accessing the display from root user is not allowed due to a security feature (cough)(cough). They said you could work around by running this command before attempting to run gksu:

xhost si:localuser:root

Another way is to just start your Ubuntu system with conventional Xorg display system; you can set this at login, I think.

I never used Ubuntu 17 though, and definitely not a Wayland user. This is probably one of the reasons that Ubuntu 18/LTS will go back to use classic Xorg by default.

Important note: If otherusername of yours is not root, no matter that you're using Wayland or classic Xorg, you need to run following command before running your program via gksu:

xhost si:localuser:otherusername

UPDATE:

The above solution is not working for Ubuntu 17.04 Xorg out of the box:

$ xhost si:localuser:root
localuser:root being added to access control list
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  109 (X_ChangeHosts)
  Value in failed request:  0xe
  Serial number of failed request:  7
  Current serial number in output stream:  9

It looks like that Ubuntu Xorg "server is not built with SECURE_RPC support, so attempting to add a FamilyNetname (0xfe) host fails."

So no out of the box solution for Ubuntu yet (but this remains as the answer until a working one exist).

xpt
  • 9,385
  • 44
  • 120
  • 178
0

Check your DISPLAY environment variable; it looks like the new user is trying to use display :2, which probably doesn't have an X server attached.

You can try something like: export DISPLAY=localhost:0.0, which should tell otherusername's X application to use the current user's X server. (I'm pretty sure this is a hack, because this variable should be configured correctly without having to set it, some more details here.)

trapezoid
  • 197
-1
  1. assign the password to this otheruser. on behalf of the superuser:

    passwd otheruser

  2. If the sudo program is installed, add the following line to /etc/sudoers, for example:

    user ALL = (otheruser) ALL

this will allow the user to execute any programs / commands on behalf of the user otheruser:

`$ sudo -u otheruser xterm`

The user's user password will be requested.

can be done without a password request by adding the NOPASSWD directive: to the above line:

user ALL = (otheruser) NOPASSWD: ALL

original - https://ru.stackoverflow.com/questions/473607/%D0%92%D1%8B%D0%BF%D0%BE%D0%BB%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5-%D0%BA%D0%BE%D0%BC%D0%B0%D0%BD%D0%B4%D1%8B-%D0%BE%D1%82-%D0%B4%D1%80%D1%83%D0%B3%D0%BE%D0%B3%D0%BE-%D0%BF%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D1%82%D0%B5%D0%BB%D1%8F

Many help additional flags -c or -p

Alex_Krug
  • 332