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.

6 comments

Vignesh

Vignesh

I am using “Linux raspberrypi 6.1.0-rpi7-rpi-v8”.
This didn’t work,
But the built-in Main Menu Editor under Preferences in the RPi menu as suggested by Chris worked..

1. Click on Rpi Menu
2. Select Preferences and click on Main Menu Editor
3. Main Menu Editor window will open, click on New Item
4. Name: Lock, Command:/usr/bin/dm-tool lock, Comment: Lock and click OK
5. Click OK again
6. I had to reboot to see the “Lock” appear in the Rpi Menu (I may be wrong). But it works after reboot for sure.

I am using “Linux raspberrypi 6.1.0-rpi7-rpi-v8”.
This didn’t work,
But the built-in Main Menu Editor under Preferences in the RPi menu as suggested by Chris worked..

1. Click on Rpi Menu
2. Select Preferences and click on Main Menu Editor
3. Main Menu Editor window will open, click on New Item
4. Name: Lock, Command:/usr/bin/dm-tool lock, Comment: Lock and click OK
5. Click OK again
6. I had to reboot to see the “Lock” appear in the Rpi Menu (I may be wrong). But it works after reboot for sure.

Duane Gustrowsky

Duane Gustrowsky

Thank you for this detailed post!
The only way I could get the lock screen menu option to appear was to modify ~/.config/lxpanel/LXDE-pi/panels/panel.
The menu option would NOT appear after modifying the following:
/etc/xdg/lxpanel/LXDE-pi/panels/panel
/etc/xdg/lxpanel/LXDE/panels/panel
/etc/xdg/lxpanel/default/panels/panel

Exactly the same results on two different Pi 4b units, both running current 64-bit Pi OS 4.3 September 2022 release.

Thank you for this detailed post!
The only way I could get the lock screen menu option to appear was to modify ~/.config/lxpanel/LXDE-pi/panels/panel.
The menu option would NOT appear after modifying the following:
/etc/xdg/lxpanel/LXDE-pi/panels/panel
/etc/xdg/lxpanel/LXDE/panels/panel
/etc/xdg/lxpanel/default/panels/panel

Exactly the same results on two different Pi 4b units, both running current 64-bit Pi OS 4.3 September 2022 release.

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.