Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I lock my desktop screen from the command line?

share|improve this question

3 Answers 3

up vote 42 down vote accepted

You can lock the computer by running gnome-screensaver-command with the -l flag like so:

gnome-screensaver-command -l

However this will only work if you have Gnome Screensaver running for your session (should be - unless you've disabled it) you can start that from the commandline with:

gnome-screensaver
share|improve this answer
1  
cinnamon-screensaver-command -l for cinnamon! ;)) –  user128334 Jan 5 at 17:28
gnome-screensaver-command -l

If you're in a different (desktop) session (e.g. virtual console, switched to another login, SSH), specify the display explicitly (:0 is the default display):

DISPLAY=:0 gnome-screensaver-command -l

To unlock, use the -d (--deactivate) option.

share|improve this answer
    
can you clarify me the DISPALY=:0 option? –  Renjith G Oct 16 '10 at 19:29
1  
Sorry for my English... DISPLAY is a variable and define in which display an X Window System program renders to (it can be another monitor). In TTY this variable is empty. By default, first display is ":0.0". So use DISPLAY=:x before your command, indicates in which display run the command. And use DISPLAY=:0 or DISPLAY=:0.0 indicates: run the program in the first display. –  Snip Oct 16 '10 at 20:46
    
@RenjithG this is quite clear if you think about it, also please do not be rude to the author of the previous comment. –  hexafraction May 2 '12 at 18:02

gnome-screensaver-command --lock will do it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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