Lock screen from command line

How to lock screen and at the time of unlock should ask password? How to do it from command prompt?

I have tried:

  gnome-screensaver-command -l

But not asking password at the unlock time.


No need of a command line: Ctrl+Alt+L will do that immediately for you.

Edit:

That has nothing to do with the command. You have to go to your System Settings, and check that password is required to disable screensaver. In Gnome, open 'system settings' and click 'brighness and lock' and toggle the lock to ON.


gnome-screensaver-command -l

gnome-screensaver-command -a

refer here https://askubuntu.com/questions/184728/how-do-i-lock-the-screen-from-a-terminal