Ubuntu – Unlock login screen using command line

command linegnomelock-screen

Is it possible to unlock the 13.04 Gnome shell login screen
from a command line? A user is logged in to Gnome shell, I can log in to a console as this user. I also have root access.

This is for accessing an active X11 display through VNC, without having to enter the password.

Executing

gnome-screensaver-command -d

as suggested in a blog post didn't help.

login screen

Best Answer

I'm assuming you have a recent linux system with systemd (e.g. Ubuntu 16.04 or newer).

If you need to unlock your own session, just run loginctl unlock-session (no root required because it's your own session). If you have multiple sessions and want to select just one, run loginctl list-sessions to identify session and then run e.g. loginctl unlock-session c187.

If you need to unlock all sessions, just run sudo loginctl unlock-sessions. Note that this will immediately unlock ALL sessions no matter which user is running the screen saver.


If you need more information to identify the correct session, you can try something like this:

loginctl list-sessions --no-legend | while read id rest; do echo; loginctl show-session $id; done