How to Enable Screen Locking in a Minimal Setup on Arch Linux
Categories:
5 minute read
When working with a minimal Arch Linux setup, especially one without a full-fledged desktop environment like GNOME, KDE, or XFCE, configuring basic features such as screen locking requires a bit more manual work. Unlike complete desktop environments, minimal setups typically use lightweight window managers (like i3, bspwm, or Openbox) and don’t come with integrated session management or lock screen utilities out of the box.
In this guide, we’ll explore how to enable screen locking on Arch Linux in such a minimal environment. We’ll cover necessary packages, configuration examples, and tips for integrating screen locking with idle timers and suspend features.
1. Why Screen Locking Matters
Screen locking is not just about convenience—it’s about security and privacy. When you step away from your computer, a locked screen ensures that no one else can access your system or view sensitive information. In multi-user or shared workspaces, this becomes even more crucial.
2. Assumptions and Prerequisites
Before proceeding, we’ll assume:
- You have a working minimal Arch Linux setup.
- You are using a window manager (like i3, bspwm, Openbox, etc.).
- You have a display server running (either Xorg or Wayland—we’ll focus on Xorg in this guide).
- You have basic knowledge of the terminal and configuration files.
3. Choosing a Screen Locker
There are several popular screen locking tools suitable for minimal setups. Here are the most commonly used:
Locker | Description |
---|---|
slock | Ultra-minimal, simple screen locker from suckless.org |
xlockmore | Classic screen locker with graphical effects |
i3lock | Lightweight, customizable locker often used with i3wm |
i3lock-color | A community fork of i3lock with enhanced color and image support |
betterlockscreen | Wrapper around i3lock-color with extra features |
For this guide, we’ll use i3lock and briefly mention alternatives.
4. Installing i3lock
To install i3lock
, use pacman
:
sudo pacman -S i3lock
Alternatively, for enhanced visuals, you can install the community-maintained i3lock-color
:
yay -S i3lock-color
Note: If you’re not using an AUR helper like
yay
, you’ll need to install one or build AUR packages manually.
5. Basic Usage of i3lock
You can lock the screen with a simple command:
i3lock
By default, it shows a blank screen with a password prompt.
You can customize the appearance:
i3lock -c 000000
This sets the background color to black. You can experiment with other flags like --blur
, --image
, etc. (especially if using i3lock-color).
6. Binding Screen Lock to a Shortcut
To improve usability, bind the screen lock to a convenient key. The method varies depending on your window manager.
i3 Window Manager
Edit your ~/.config/i3/config
file:
# Lock screen with Mod+Shift+X
bindsym $mod+Shift+x exec i3lock -c 000000
bspwm + sxhkd
In ~/.config/sxhkd/sxhkdrc
:
super + shift + x
i3lock -c 000000
Reload sxhkd
after making changes:
pkill -USR1 -x sxhkd
7. Locking on Suspend or Lid Close
To lock the screen when the system suspends or the laptop lid is closed, we can use systemd hooks.
Create a systemd Sleep Hook
Create a new service:
sudo nano /etc/systemd/system/lock@.service
Paste the following:
[Unit]
Description=Lock screen before sleep
Before=sleep.target
[Service]
User=%i
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock -c 000000
[Install]
WantedBy=sleep.target
Enable the service for your user:
sudo systemctl enable lock@your_username.service
Replace
your_username
with your actual username.
This ensures your screen locks before going to sleep.
8. Locking on Idle (Using xautolock
)
To automatically lock the screen after a period of inactivity, use xautolock
.
Install xautolock
sudo pacman -S xautolock
Add to Startup
In your startup script (e.g., .xinitrc
or your WM autostart file):
xautolock -time 10 -locker "i3lock -c 000000" &
This locks the screen after 10 minutes of inactivity.
You can customize the time (
-time
) and even use-notify
options to show a warning before locking.
9. Using betterlockscreen
(Optional)
If you want enhanced visuals (blurred wallpapers, custom fonts, etc.), consider using betterlockscreen
.
Install from AUR
yay -S betterlockscreen
Setup
First, set a wallpaper:
betterlockscreen -u ~/Pictures/your_wallpaper.jpg
Then lock:
betterlockscreen -l
You can also integrate this with xautolock
, sleep hooks, or key bindings just like i3lock
.
10. Wayland Considerations
If you’re using a Wayland-based compositor (like sway
instead of i3), i3lock won’t work because it’s Xorg-based. Instead, use swaylock:
sudo pacman -S swaylock
Usage is similar:
swaylock
You can integrate swaylock with sway’s configuration file and idle daemon (swayidle
) for similar results.
11. Troubleshooting Tips
Screen doesn’t lock on suspend?
- Ensure the
DISPLAY=:0
environment variable is correctly set. - Use
loginctl seat-status
to verify session info. - Try hardcoding your X display and DBUS session if necessary:
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/your_username/.Xauthority
i3lock shows a black screen but doesn’t prompt?
- Make sure your user has permission to access the X session.
- If using LightDM or another display manager, the DISPLAY might be
:1
, not:0
.
12. Summary
Here’s a recap of what we’ve covered:
- Installed a screen locker (
i3lock
orbetterlockscreen
) - Bound it to a hotkey for quick access
- Set up auto-locking using
xautolock
- Locked screen on suspend via systemd hooks
- Covered minimal Wayland alternatives (
swaylock
)
While a minimal Arch Linux setup offers flexibility and speed, it also means you need to piece together functionalities manually. Setting up screen locking is one such task, but with a few commands and some configuration, you can achieve a secure and reliable setup that doesn’t rely on a full desktop environment.
13. Final Thoughts
Minimal setups are great for control and performance, and learning to configure basic features like screen locking helps deepen your understanding of the Linux system architecture. Whether you stick with a simple i3lock
or go for something more elaborate like betterlockscreen
, the key takeaway is that even in minimalism, usability and security can go hand in hand.
If you’re already using other tools to manage power or sessions (like acpid
, lightdm
, elogind
, or xfce4-power-manager
), they might conflict or offer overlapping features—always test thoroughly after changes.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.