Lock your screen using command line

Hi friends,
I read one article today and that was fantastic.I am sharing that article here hope you all like it.

Lock your Screen using command line in Fedora 10 and Ubuntu.

This command is extraordinary for who work on terminal continuously and want to step away for some movements.

gnome-screensaver-command –lock

NOTE –In this command, where you see “–lock”, it is really 2 hyphens with no spaces in between, followed by “lock” …  – – lock. WordPress renders two hyphens put together as… –

When you execute above command then it will activate your screen saver and prompt for password to login.But as i metioned that command is pretty long so you need to create alias for that.To create alias Follow below method.

Open your .bashrc file into your favorite editor i am using vim as my editor.before editing file dont forget to make backup.
vim .bashrc (if you are not at home directory prompt then vim /home/<user-name>/.bashrc)

Now just move to end of file and paste below content.
alias lock=’gnome-screensaver-command –lock’

Save & Exit from File.

Now above commands tells your ubuntu or fedora that if you type in lock ,it actually executes gnome-screensaver-command –lock

Enjoy Lock Screen from Command Prompt 🙂

source :- http://howto-ubuntu.com/2008/12/11/how-to-lock-your-screen-from-the-command-line/
Content Protection by DMCA.com

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.



  • Jim (JR) says:

    This is SWEET!

    I have been wanting to put a “lock screen” icon on my desktop (in Ubuntu) for a while now as I change systems via a KVM frequently while I work – and returning to Ubuntu from another KVM port always leaves the mouse doing weird things.

    Now all I have to do is click the icon (launcher!) and I’m done!

    BTW the default launcher icon is totally lame, so I changed it to the “gnome encrypted locked” icon (a padlock) which works perfectly.

    Thanks! This is totally awesome!

    Jim (JR)

  • Alberto Rojas says:

    Many thanks,

    For CentOS works:

    gnome-screensaver-command -l or gnome-screensaver-command –lock

  • Galileo says:

    Thanks, I wish this was easier to find. This is exactly what
    I was looking for works great!!

  • Marica Frisell says:

    Fantastic article !

  • Tejas Barot says:

    Which Distribution you are using? If you are using Fedora then install xlock package by following yum -y install xlockmore* and execute xlock command to lock your root screen. I hope its available for Ubuntu also. But I didnt tried this in ubuntu

    Enjoy. 🙂

  • KS Solanki says:

    i have to lock screen for root ….how can i do that ….plz tell me some solution.

  • Hi, interesting post. I have been wondering about this topic,so thanks for writing. I will certainly be subscribing to your blog. Keep up the good work

  • GlenStef says:

    Everything dynamic and very positively! 🙂
    Thank you


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Are you Human ? * Time limit is exhausted. Please reload CAPTCHA.