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
dbus-sendto call a method.
--dest=org.gnome.ScreenSavertells it the command is in
org.gnome.ScreenSaver.Locktells 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.