Introduction: Lock Your Raspberry Pi From a Menu

About: Systems Administrator and Software Programmer.

Lock your PC if you need to leave your Raspberry Pi for a moment. Else evil doers may steal information while you are away.

Step 1: Configure Menu

Open terminal emulator

cd ~/.config/lxpanel/LXDE-pi/panels<br>vi panel

Type the following in the plugin menu stanza

separator {
}

item {

name=Lock...

image=gnome-lockscreen

action=/usr/bin/dm-tool lock

}

Your final panel file should look like the following:

# lxpanel config file. Manually editing is not recommended.

# Use preference dialog in lxpanel to adjust config when you can.

Global {

edge=top

allign=left

margin=0

widthtype=percent

width=100

height=36

transparent=0

tintcolor=#ffffff

alpha=0

autohide=0

heightwhenhidden=2

setdocktype=1

setpartialstrut=1

usefontcolor=0

fontsize=12

fontcolor=#b25d5d

usefontsize=1

background=0

backgroundfile=/usr/share/lxpanel/images/background.png

iconsize=36

}

Plugin {

type=space

Config {

Size=2

}

}

Plugin {

type=menu

Config {

name=Menu

image=/usr/share/raspberrypi-artwork/raspitr.png

system {

}

separator {

}

item {

name=Run...

image=gnome-run

command=run

}

separator {

}

item {

name=Shutdown...

image=gnome-logout

command=logout

}

separator {

}

item {

name=Lock...

image=gnome-lockscreen

action=/usr/bin/dm-tool lock

}

}

}

Plugin {

type=space

Config {

Size=8

}

}

Plugin {

type=launchbar

Config {

Button {

id=/usr/share/applications/epiphany-browser.desktop

}

Button {

id=/usr/share/applications/pcmanfm.desktop

}

Button {

id=/usr/share/applications/lxterminal.desktop

}

Button {

id=/usr/share/applications/wolfram-mathematica.desktop

}

Button {

id=/usr/share/applications/wolfram-language.desktop

}

}

}

Plugin {

type=space

Config {

Size=8

}

}

Plugin {

type=taskbar

expand=1

Config {

tooltips=1

IconsOnly=0

ShowAllDesks=0

UseMouseWheel=1

UseUrgencyHint=1

FlatButton=0

MaxTaskWidth=200

spacing=1

GroupedTasks=0

}

}

Plugin {

type=space

Config {

Size=2

}

}

Plugin {

type=tray

Config {

}

}

Plugin {

type=space

Config {

Size=2

}

}

Plugin {

type=cpu

Config {

ShowPercent=1

}

}

Plugin {

type=dclock

Config {

ClockFmt=%R

TooltipFmt=%A %x

BoldFont=0

IconOnly=0

CenterText=0

}

}

Plugin {

type=space

Config {

Size=2

}

}

Save the file

Compare your file with the file that I have uploaded

Step 2: Test

Reboot the Rasbpeberry Pi

Open the terminal emulator:

Restart lxpanel

lxpanelctl restart

OR if restarting the lxpanel did NOT work, reboot RPi

sudo reboot

Click on the menu

The menu item "Lock" will be shown

Click on the menu Lock

Raspberry Pi will display a login screen

Enter password

Your applications that are opened before locking event will still be available.