5

I have an openSUSE machine which I log on to with ssh -X. I don't want to log in as root but I do want to run graphical Yast. Inside the ssh session sudo starts the console version of Yast. However, in Gnome or KDE it is possible to start Yast as a normal user and then give a root password in a window to run Yast as root.

How can I do that from my ssh session?

Andrew J. Brehm
  • 379
  • 1
  • 3
  • 14

2 Answers2

2

Log in as "normal" user (using X11-forward), then su - -c yast2.

Nils
  • 18,202
  • 11
  • 46
  • 82
  • Ta. That worked. – Andrew J. Brehm Feb 09 '12 at 22:10
  • what if I would like to use my password (sudo) not root password? – mpapis Aug 22 '12 at 20:21
  • @mpapis should work via sudo, too, but I did not check. `sudo` is more common on Debian-based systems. You might have to force TTY-allocation to make it work in a single command via ssh. – Nils Aug 26 '12 at 20:38
  • `sudo` most likely has `env_reset` which means most of environment variables are lost, including `DISPLAY`, you would have to write it like `sudo DISPLAY=$DISPLAY yast2`, but this still does not work when `ssh -Y` is used as authentication to X server is lost with sudo, so any hints? – mpapis Aug 27 '12 at 01:54
1

X uses a variable called DISPLAY in order to determine where to send the "information" related to the display. When you use ssh -X, SSH creates a DISPLAY variable and X programs use that.

When you use sudo, it gives you a restricted environment. To avoid this, you could try the command:

sudo -E yast

This will run yast but preserve the environment. This may or may not work depending on your sudoers settings, in particular setenv and the SETENV tag for commands (with the ALL command tag, SETENV is implied).

To just set DISPLAY (in case it doesn't transfer over), you could do this too:

sudo DISPLAY=$DISPLAY yast

This is subject to the same restrictions as the first command.

Mei
  • 1,136
  • 9
  • 12
  • About the "-" sudo complains "-: command not found". Without the "-" both commands just start text-mode yast as root, not the X version. – Andrew J. Brehm Feb 09 '12 at 07:21
  • That was a syntax error on my part (fixed above). I would try something like `sudo su -` and then `echo $DISPLAY` and see what it says. I might also try an X-only program to see what happens. If `DISPLAY` is set right and the access is good, it should work. You could try this sequence too: `xhost +; sudo -E yast` - that grants access to the display, but I don't think that's right. – Mei Feb 09 '12 at 14:19
  • I do wonder how Yast decides whether to display X or use the console. – Andrew J. Brehm Feb 09 '12 at 15:54
  • yast2 automatically chooses based on modules loaded and on the `DISPLAY` variable; check the `DISPLAY` variable and make sure that the display works. It is possible to login with `ssh -X` and have the remote SSH deny X forwarding; so check `DISPLAY`. Also make sure that you have the X libraries loaded on the remote system; if they're not available, it won't work. You can affect the GUI that yast2 uses through a setting in `/etc/sysconfig/yast2`: `WANTED_GUI="gtk"` (or `qt`). If you have X available on the remote system, try `xclock` and `sudo xclock` to see if the display actually works. – Mei Feb 09 '12 at 16:57
  • X works for programs that run without sudo. sudo xlogo Error: Can't open display: – Andrew J. Brehm Feb 09 '12 at 17:14
  • Are you making sure that `DISPLAY` is set after using `sudo`? Also check for `XAUTHORITY`; both will need to be set in your `sudo` environment. If `sudo` is stripping out these variables from your environment, then you'll have to set them by hand or configure `sudo` to not do this. – Mei Feb 09 '12 at 17:49