How to lock your screen from the command line

This could be very useful to you if you’re working in the terminal and need to step away for a moment. You can achieve a locked screen, just like when you do it the graphical way, with this command entered at the command line, or cli…



gnome-screensaver-command --lock


This will instantly launch your screensaver, and lock your computer’s screen. Your password will be required to gain access to your system once this is activated.

That command is pretty long, and typing it out would probably get on my nerves. You can use an alias to effectively shorten it. Here’s how we’ll do that, also at the command line…

Let’s say we want to be able to type in lock, to lock the screen. If I just type in lock, I get nothing. So I need to create an alias for this command. An alias is just like what it sounds like. It’s assigning another name to a certain command. At the command line enter…

gedit .bashrc


There’s a certain section of this file that talks about aliases. You can add this line of text to that section of the file…


alias lock='gnome-screensaver-command --lock'


This tells Ubuntu that when you type in lock, it executes gnome-screensaver-command –lock. Click the Save button and close the text editor. The next time you login, the change will have taken effect. Try it out and see how you like it.

Here’s what it should look like…

screenshot-bashrc-gedit

  • Share/Bookmark

15 comments to How to lock your screen from the command line

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>