-2

From https://unix.stackexchange.com/a/505644/674

When you're using SSH, you can access the screen you're connected from by using ssh -X or ssh -Y . Programs can perfectly run on a machine and display on another one. So if you run light-locker through SSH on the remote machine, it will lock your local display and not the remote one (just as running gnome-terminal or any other command will run it on the remote machine but display it locally).

if you want the screen to lock again, yes, you'll have to restart it, but be careful to restart it from the X session you want to lock, not from ssh.

I ssh to a machine, and then want to lock its screen. Could anyone tell me why I failed and what I shall do? Thanks.

$ xscreensaver-command -lock
xscreensaver-command: warning: $DISPLAY is not set: defaulting to ":0.0".
xscreensaver-command: no screensaver is running on display :0.0

$ DISPLAY=:0 xscreensaver-command -lock xscreensaver-command: no screensaver is running on display :0


Not sure how one can tell there is no X server running on the remote host:

$ ps -A | grep -i xorg
  448 ?        00:00:29 Xorg
  605 ?        00:00:27 Xorg
  766 tty7     05:19:26 Xorg
 2175 ?        00:02:58 Xorg
 3343 ?        00:00:24 Xorg
 8520 ?        00:00:28 Xorg
12564 ?        00:00:22 Xorg
24655 ?        00:00:13 Xorg
26692 ?        00:00:28 Xorg
26704 ?        00:00:25 Xorg
26852 ?        00:00:29 Xorg
27034 ?        00:00:23 Xorg
Tim
  • 101,790
  • Read my answer for you in another question, the X server is not running on your remote machine, so you fail and will never succeed because your remote machine has no screen at all. – 炸鱼薯条德里克 Mar 15 '19 at 17:18
  • 2
    If the server has a gnome graphical desktop, you can lock the screen according to this link. I tested it right now via ssh (from another computer) with and without prefix DISPLAY=:0 as in your question. It works in both cases. – sudodus Mar 15 '19 at 17:26
  • @sudodus (1) The remote is using LXDE and has no gnome-screensaver installed. What command does dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock invoke? (2) How can you unlock the remote desktop? – Tim Mar 15 '19 at 17:53
  • @sudodus https://unix.stackexchange.com/questions/506567/what-screen-locking-program-does-dbus-send-type-method-call-dest-org-gnome – Tim Mar 15 '19 at 18:00
  • @炸鱼薯条德里克 Where is "my answer for you in another question"? How do you know "the X server is not running on your remote machine"? – Tim Mar 15 '19 at 18:00
  • I found the link to that command line and tested that it works. But I don't know the details you are asking about. Let us hope that someone else will chip in and help you get further :-) – sudodus Mar 15 '19 at 18:07
  • You seems want to do this purely within the same machine on the remote (you said you have Xorg running on remote, and you run your commands on remote and want to lock the display of the remote, and you set DISPLAY to an IPC address), while you mention ssh -X, which is completely not needed, people use this to do X forwarding(X server on SSH client side), which isn't what you need if I'm correct about the first sentence. – 炸鱼薯条德里克 Mar 16 '19 at 00:33
  • If I'm correct about the first sentence, then ssh's connection is simply used to provide you a shell on remote to control the remote, then you simply don't have xscreensaver running on that display(:0 on the remote, notice it's IPC address, not network address), as indicated by the err message. You got many Xorg on remote, don't know which is listening on ":0 on remote". – 炸鱼薯条德里克 Mar 16 '19 at 00:38
  • Anyway, you mentioning ssh -X and the big chunk of quote is very confusing, if I'm right about your intension, then there's no need to mention ssh, because you can just sit in front of the remote, get a login shell, run the same command and get the same result. https://unix.stackexchange.com/questions/506488/how-can-i-find-the-mapping-on-display-after-ssh-x You need to know which connections are involved in ssh forwarding. – 炸鱼薯条德里克 Mar 16 '19 at 00:43

2 Answers2

1

You need to learn about the workings of X. You have your local machine LOC and ssh to the remote machine REM. You have two X displays: LOC:0.0 and REM:0.0 . When you run ssh -X REM from LOC you create a new virtual X display on REM which is "REM:10.0" and points back to "LOC:0.0". So when you run a program on REM, its graphics get send to REM:10 and from there to LOC:0.0 where they appear.

If you run a VNC server on REM, it will appear as "REM:1.0" (for instance). You can have many different X displays running on the same machine, sending output from applications to different physical or virtual screens.

Now while you're connected on REM, if there is a user logged locally, using "REM:0.0", "REM:1.0" or other X displays (VNC are just special X displays) you can display things on this screen through ssh by changing the value of the special variable "DISPLAY".

If you connect on the local console of a machine, and run echo $DISPLAY you'll get :0.0

If you connect from LOC to REM with ssh and want to display applications you launch on REM's screen (REM:0.0), change the value of DISPLAY:

export DISPLAY=:0.0

Run a program, and it will display on REM screen (if a session is opened by the same user, of course).

In your case, there must be an open session on "REM:0.0" which isn't the case. If the session is ran using VNC, it must be "REM:1.0", so to run xscreensaver there you must set DISPLAY accordingly:

export DISPLAY=:1.0
xscreensaver
xscreensaver-command -lock
wazoox
  • 1,364
  • ssh -X simply request sshd to start listening on 6010, sshd doesn't create X display nor provide X server functionality. VNC server is not a display, some VNC server aren't X server, even when they're, VNC is still a completely different thing from X. Login through local console never ensures DISPLAY env. – 炸鱼薯条德里克 Mar 16 '19 at 23:45
  • @炸鱼薯条德里克 X is complex enough to understand I try to keep the explanation simple and to talk only about what OP is trying to do. On Linux/Unix, when you run an autonomous VNC server it can be considered as another X server and behave as such even though it is something else, using a different protocol, etc. and you can manipulate windows exactly the way I described, it works. – wazoox Mar 18 '19 at 08:34
0

For this solution you will have to install xdotool. This works perfectly on my linux mint

export DISPLAY=:0
xdotool key Ctrl+alt+l