How to lock your Raspberry Pi Screen

How to lock your Raspberry Pi Screen

Many of you will be familiar with the Windows screensaver/lock screen.  If you are going to leave your PC alone for any amount of time where others may have access to it (like in a busy office) then it is advisable to lock it every time you walk away from it using the Win+L key combinations.

But we are talking about the Raspberry Pi here.  If you are running it headerless or in command line mode and you are not logged in, then anyone who has access to it will need to log in (you have changed the default password, haven’t you?).

But what if you have a Raspberry Pi in Desktop mode?  The same applies to a Raspberry Pi as it does to a PC; you should lock the screen if you walk away from it.  This is especially important if you are using a Pi as a server and have Desktop mode running to help with management of a service.

Banking on your Pi

A ‘screensaver’ is not installed by default, but a lock screen is; it’s has just not been put onto the menu.  You can do that by editing a file that defines how your menus and toolbar appears.

Open a terminal window, and type in*:

sudo nano /etc/xdg/lxpanel/LXDE-pi/panels/panel

Editing the menus using nano

Scroll down (using the cursor keys) to the section that starts:

Plugin {

  type=menu


Finding the right part of the configuration file

Move to the end if this section, and type in (or copy/paste) the following:

    item {
      name=Lock…
      image=gnome-lockscreen
      action=/usr/bin/dm-tool lock
    }

The file should look like this:


 Adding the lock menu

Save the file by typing typing Ctrl+x (the Ctrl key, with x), then ‘y’ to the prompt to save, and the Enter key.

After your next reboot, you will now see a new item at the bottom of your menu:


The Lock… menu

Now, when you are going to be away from your Raspberry Pi, all you need to do to secure it is to click on the Lock… menu and the screen will be locked:


The Lock… screen

Just type in your password, and your Pi and you can resume from where you left off.

* On older versions of Raspbian, you may find the configuration file in ~/.config/lxpanel/LXDE-pi/panels/panel instead.

4 comments

Chris

Chris

Bummer, not working anymore (Nov 2022). :-(
If anyone has suggestions for how to fix this, or other ways to implement a quick lock screen in Raspbian, we would appreciate it!

Bummer, not working anymore (Nov 2022). :-(
If anyone has suggestions for how to fix this, or other ways to implement a quick lock screen in Raspbian, we would appreciate it!

Chris

Chris

Use the built-in Main Menu Editor under Preferences in the RPi menu. You can add an item to the drop-down and point it to run the command /usr/bin/dm-tool lock. That will immediately add the Lock item to the menu without having to reboot. [running an RPi 4B with 64 bit OS and Desktop]

Use the built-in Main Menu Editor under Preferences in the RPi menu. You can add an item to the drop-down and point it to run the command /usr/bin/dm-tool lock. That will immediately add the Lock item to the menu without having to reboot. [running an RPi 4B with 64 bit OS and Desktop]

Sergey

Sergey

It’s now in ~/.config/lxpanel/LXDE-pi/panels/panel

It’s now in ~/.config/lxpanel/LXDE-pi/panels/panel

Reiner

Reiner

Hi,
this is not working on
Linux rpi3 5.15.61-v8+ #1579 SMP PREEMPT Fri Aug 26 11:16:44 BST 2022 aarch64 GNU/Linux (issue : Debian GNU/Linux 11)
It seems the file is totally ignored as even duplicating an existing entry or seperator entry is not reflected in the Menu structure after reboot.
Any suggestings?
Thank you very much
Reiner

Hi,
this is not working on
Linux rpi3 5.15.61-v8+ #1579 SMP PREEMPT Fri Aug 26 11:16:44 BST 2022 aarch64 GNU/Linux (issue : Debian GNU/Linux 11)
It seems the file is totally ignored as even duplicating an existing entry or seperator entry is not reflected in the Menu structure after reboot.
Any suggestings?
Thank you very much
Reiner

Leave a comment

All comments are moderated before being published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.