2

How do I unlock the lock screen in Unity from command line?

gnome-screensaver-command -l locks the screen, but gnome-screensaver-command -d doesn't unlock the lockscreen.

Is there another way to unlock the lock screen from the command line? Not via ssh, via script, for example:

gnome-screensaver-command -l && sleep 5 && <command to unlock>
muru
  • 193,181
  • 53
  • 473
  • 722
Gugi
  • 33
  • 1
  • 5
  • 1
    `gnome-screensaver-command -d` doesn't unlock it because [it's not meant to](http://manpages.ubuntu.com/manpages/xenial/en/man1/gnome-screensaver-command.1.html). It only deactivates the screensaver, but it won't log in as any user, that's why it doesn't work. – M. Becerra Mar 06 '17 at 11:36
  • 2
    Possible duplicate of [unlock screen from command line](http://askubuntu.com/questions/505177/unlock-screen-from-command-line) – M. Becerra Mar 06 '17 at 11:37
  • @M.Becerra is there an easy way to do it, if no with this command? i saw that post, but i could find a satisfying answer – Gugi Mar 06 '17 at 11:40
  • Depends on what you want to do exactly. Do you want to **lock** (so that you would have to log in again) or just show the screensaver? – M. Becerra Mar 06 '17 at 11:43
  • If you read the `man gnome-screensaver-command` , it says for `-d` "unblank the screen". So it is not meant to be unlocking if your session is locked. Only turning on the display if it has been blanked out/turned off. – Sergiy Kolodyazhnyy Mar 06 '17 at 11:52
  • i want to lock so that i have to log in again and a script which is able to unlock (after a certain amount of time, or when executed via ssh for example) – Gugi Mar 06 '17 at 12:27

1 Answers1

4

For Ubuntu 16.04 and later:

loginctl unlock-sessions

No need for root, but needs session permission obviously.

Note:
By default gnome-screensaver-command -d doesn't work anymore in Unity but with this workaround (enable on-screen keyboard) it does. Works for both 14.04 and 16.04.

lemonsqueeze
  • 1,624
  • 12
  • 17