8

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.

Toto
  • 17,001
  • 56
  • 30
  • 41
user3134198
  • 287
  • 1
  • 2
  • 10

5 Answers5

4

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.

Rolf
  • 315
  • 3
  • 10
4

gnome-screensaver-command -l

gnome-screensaver-command -a

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

Miqdad Ali
  • 349
  • 3
  • 8
  • 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! – user3134198 Jan 28 '14 at 10:33
  • No one asked for gnome, i use DWM, so I need a proper command for terminal – holms Aug 01 '18 at 16:27
2

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.

Rolf
  • 315
  • 3
  • 10
  • 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](/review/low-quality-posts/659625) – Burgi May 30 '17 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 '17 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 '18 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 '18 at 22:02
1

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

xdg-screensaver lock
atomsymbol
  • 130
  • 6
1

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.

MariusMatutiae
  • 46,990
  • 12
  • 80
  • 129