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,890
  • 56
  • 97
  • 151

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,890
  • 56
  • 97
  • 151
-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,890
  • 56
  • 97
  • 151