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).
Asked
Active
Viewed 2,719 times
0
2 Answers
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
-
-
@muru: Thanks for the hint. I only skimmed over the comment section. Now there's a different command. – David Foerster May 22 '17 at 08:37
-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

TomaszF
- 1
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