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.

  • Have you tried running gnome-screensaver with --debug while applying commands to it with gnome-screensaver-command? Have you searched RedHat knowledgebase for known bugs against gnome-screensaver?
    – user260419
    Jan 28, 2014 at 8:57
  • 1
    Which Desktop Environment are you using? Gnome, KDE, XFCE, LXDE,Mate,Cinnamon,...? Jan 28, 2014 at 8:59
  • I am using Gnome Jan 28, 2014 at 9:03
  • are you trying through ssh? Jan 28, 2014 at 9:09
  • I am inside Vmware and directly using on "Terminal" Jan 28, 2014 at 9:10

5 Answers 5


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


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.

  • It is locking but again at the time of unlock it is NOT asking password. Does it asks for password at the time of unlock in other Linux flavors? Jan 28, 2014 at 9:05
  • @user3134198 See my edit Jan 28, 2014 at 9:11
  • System -> Preferences -> Screensaver does not provide provision to check password is enabled or sated, Please could you guide for that? Jan 28, 2014 at 9:14
  • @user3134198 Not what I said: System settings -> Brightness and Lock -> Lock -> On. Jan 28, 2014 at 9:19
  • 2
    "How to do it from command prompt?" Emphasis added. I don't consider comments by the OP to be part of the question. Aug 23, 2014 at 19:41

gnome-screensaver-command -l

gnome-screensaver-command -a

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

  • Hi when I logged as a ordinary user then Ctrl + Alt + L locks the screen and also at the time of unlock asks for a password, but when I logged in as a root it locked the screen but didn't asked for a password. Many thanks! Jan 28, 2014 at 10:33
  • No one asked for gnome, i use DWM, so I need a proper command for terminal
    – holms
    Aug 1, 2018 at 16:27

It depends on your environment, but in any case physlock (look it up) will lock your screen in whichever environment (X, Wayland, VT, or other).

No fancy colors or graphics with that one, though.

  • 2
    physlock works smoothly! thx
    – Fusho
    Mar 30, 2018 at 14:30
  • 1
    that's a nice tool although I've expected screensaver to pop up :)
    – holms
    Aug 1, 2018 at 16:28

I believe it depends on your display manager. I have lightdm so it's dm-tool lock

Lock the current seat. This will switch to a greeter with a hint that the screen is locked. You can return to this session by authenticating in the greeter.

EDIT: It looks and acts like a screen lock, but I have noticed that I can "skirt around it" by switching to a text terminal and back to the X terminal (on my machine Ctrl-Alt-F2 then Ctrl-Alt-F6 does that). dm-lock would then just exit.

I'm not sure if I'm doing something wrong here. But I am leaving these here as a pointer, I think it would still be useful information for someone.

The gnome command that other mentioned did not work for me, by the way. I do not really use Gnome on my desktop.

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    – Burgi
    May 30, 2017 at 11:59
  • @Burgi I do not think that you provided a clear explanation as to why my answer is not valid, but I did find issues with my answer. Thank you for your comment and edit. I appreciate. Please check my updated answer. Thanks.
    – Rolf
    May 30, 2017 at 14:45
  • without gnome and having lightdm this is the right way. However, I noticed what you say, did you find a solution for this strange "bug"? is it a bug?
    – Fusho
    Mar 29, 2018 at 19:04
  • 3
    @oxuf Hi, I am relying on physlock now, it locks the screen and works for X, wayland or VTs. Linux software can be very rich in bugs, so I would not be surprized if it's one. Also I don't use any DM anymore, I just log into a VT and launch startx, weston, or whatever I fancy from there. It's easy to switch between WMs with a simple .xinitrc script.
    – Rolf
    Mar 29, 2018 at 22:02

A solution that is more likely to be independent from the desktop environment in use:

xdg-screensaver lock

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.