Lock screen from command line or bash script
January 13, 2016

This tip is for Unity or GNOME users.

On Unity or GNOME, you can lock the screen from the command line. I have found this very useful. One way I have used this is to lock the screen after an installation finishes. The command itself is below:

dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock


  • The --type=method_call tells dbus-send to call a method.
  • The --dest=org.gnome.ScreenSaver tells it the command is in org.gnome.ScreenSaver.
  • The org.gnome.ScreenSaver.Lock tells it to lock the screen.

This command can be called from a bash script or the terminal. This is avaliable as a shell script from github.com/geek1011/Scripts.sh/blob/master/LockScreen/LockScreen.sh.