0

I'm looking for a command to lock user session (kinda like Super+L). I saw it for screen lock but I need something to work while I'm connected through SSH (e. g. with PuTTY).

David Foerster
  • 36,264
  • 56
  • 94
  • 147
  • I saw the question you referred to. I don't think it's working for me. When I try it I get The program 'gnome-screensaver-command' is currently not installed. You can install it by typing: sudo apt install gnome-screensaver, and I don't want to install it. – user1908466 May 21 '17 at 13:19
  • 1
    Through SSH? Do you want to lock the remote or local machine? – Melebius May 21 '17 at 13:48
  • @davidbaumann: That won't work because SSH sessions aren't normally connected to any display server and sessions that could handle these lock commands. – David Foerster May 22 '17 at 08:19
  • @user1908466: Could you please [edit] your post, when you want to add information? It’s best to have everything relevant in one place for people like me who don't read the entire comment section but focus on the question and then have to amend their answer because of that. ;-] Additionally, comments may be deleted for various reasons. Thanks. – David Foerster May 22 '17 at 08:38

2 Answers2

1

You'll need to combine of the answer of How do I lock the screen from a terminal? and How do I run a graphical application on a remote server when logged in through SSH? The former gives you multiple commands that will lock the current session but they all assume that they're executed from within that session. The latter explains how to execute a program in the context of a different session by setting an environment variable to the address of the display server running the that session. Example:

DISPLAY=:0 dbus-send --print-reply --session --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
David Foerster
  • 36,264
  • 56
  • 94
  • 147
-1

You can log out (instead of lock) the user via:

gnome-session-quit --logout

I don't think there's any other way of invoking the session lock, than gnome-screensaver-command --lock though.

David Foerster
  • 36,264
  • 56
  • 94
  • 147