Keep your Linux laptop running when you close the lid - lock the screen without suspending.
This solution configures your Linux laptop (GNOME-based) to lock the screen when you close the lid, without suspending the system. All services, SSH connections, and background processes continue running.
Perfect for:
- 🖥️ Server laptops that need to stay accessible
- 💻 Development machines running services/containers
- 🌐 Remote workstations accessed via SSH
- 🎬 Media servers or home automation systems
- ⚙️ Long-running computations
Download and install in one command:
Lock Screen Only (default):
curl -L https://raw.githubusercontent.com/Genaker/LinuxSleepServerMod/main/install.sh | bash -s lockLock Screen + Stop GUI:
curl -L https://raw.githubusercontent.com/Genaker/LinuxSleepServerMod/main/install.sh | bash -s gui-stopOr using wget:
Lock Screen Only:
wget -qO- https://raw.githubusercontent.com/Genaker/LinuxSleepServerMod/main/install.sh | bash -s lockLock Screen + Stop GUI:
wget -qO- https://raw.githubusercontent.com/Genaker/LinuxSleepServerMod/main/install.sh | bash -s gui-stopThis will automatically:
- Download the repository
- Extract files
- Run the appropriate setup script (lock or gui-stop)
- Clean up temporary files
Using wget:
# Download and extract
wget https://github.com/Genaker/LinuxSleepServerMod/archive/refs/heads/main.zip -O lockscreen.zip
unzip lockscreen.zip
cd LinuxSleepServerMod-main
chmod +x setup-lock.sh setup-gui-stop.sh uninstall.sh
# Run setup
./setup-lock.shUsing curl:
# Download and extract
curl -L https://github.com/Genaker/LinuxSleepServerMod/archive/refs/heads/main.zip -o lockscreen.zip
unzip lockscreen.zip
cd LinuxSleepServerMod-main
chmod +x setup-lock.sh setup-gui-stop.sh uninstall.sh
# Run setup
./setup-lock.shOr clone with git:
git clone https://github.com/Genaker/LinuxSleepServerMod.git
cd LinuxSleepServerMod
chmod +x setup-lock.sh setup-gui-stop.sh uninstall.sh
./setup-lock.shOption 1: Lock Screen Only
./setup-lock.shOption 2: Lock Screen + Stop GUI
./setup-gui-stop.shThese scripts will:
- Configure GNOME power settings
- Install daemon scripts (bash and Go if available)
- Set up autostart
- Start the daemon
To remove everything:
./uninstall.shgsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action 'nothing'
gsettings set org.gnome.settings-daemon.plugins.power lid-close-battery-action 'nothing'and this sudo nano /etc/systemd/logind.conf
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
Option A: Using Bash Scripts
# Create script directory
mkdir -p ~/.local/bin
# Copy the daemon script
cp lid-lock-daemon.sh ~/.local/bin/
chmod +x ~/.local/bin/lid-lock-daemon.shOption B: Using Go (Recommended for better performance)
# Install Go if not already installed
# Ubuntu/Debian: sudo apt install golang-go
# Fedora: sudo dnf install golang
# Build and install
make install
# Or manually:
go build -o lid-lock-daemon lid-lock-daemon.go
cp lid-lock-daemon ~/.local/bin/
chmod +x ~/.local/bin/lid-lock-daemon# Create autostart directory
mkdir -p ~/.config/autostart
# Copy autostart file (edit YOUR_USERNAME first)
cp lid-lock.desktop ~/.config/autostart/
# Edit ~/.config/autostart/lid-lock.desktop and replace YOUR_USERNAME with your usernameBash version:
nohup ~/.local/bin/lid-lock-daemon.sh > /dev/null 2>&1 &Go version:
nohup ~/.local/bin/lid-lock-daemon > /dev/null 2>&1 &- ✅ Locks screen when lid closes (within 1 second)
- ✅ System keeps running - no suspend
- ✅ All services active - SSH, web servers, containers
- ✅ Network stays connected - remote access available
- ✅ Background processes continue - no interruptions
lid-lock-daemon.sh- Main daemon script that monitors lid statelid-lock-stop-gnome.sh- Advanced version that also stops GUIsetup-lid-gui-sudo.sh- Helper script for sudo configurationlid-lock.desktop- Autostart configuration file
lid-lock-daemon.go- Go version of the main daemonlid-lock-stop-gnome.go- Go version with GNOME stop/startgo.mod- Go module definitionMakefile- Build and install automation
For maximum resource savings, use the version that also stops GNOME GUI:
sudo bash setup-lid-gui-sudo.shBash version:
cp lid-lock-stop-gnome.sh ~/.local/bin/
chmod +x ~/.local/bin/lid-lock-stop-gnome.sh
# Update autostart file to use lid-lock-stop-gnome.sh insteadGo version:
go build -o lid-lock-stop-gnome lid-lock-stop-gnome.go
cp lid-lock-stop-gnome ~/.local/bin/
chmod +x ~/.local/bin/lid-lock-stop-gnome
# Update autostart file to use lid-lock-stop-gnome insteadBehavior:
- Lid closes → Locks screen → Stops GNOME → Logs out
- Lid opens → Starts GNOME → Shows login screen
Check if daemon is running:
ps aux | grep lid-lock-daemonCheck lid state:
dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.DBus.Properties.Get string:org.freedesktop.login1.Manager string:LidClosedBash scripts:
Edit the script and modify sleep 1:
sleep 0.5- Faster response (more CPU)sleep 2- Slower response (less CPU)
Go versions:
Edit the Go source and modify checkInterval := 1 * time.Second:
500 * time.Millisecond- Faster response (more CPU)2 * time.Second- Slower response (less CPU)
# Stop bash version
pkill -f lid-lock-daemon.sh
# Stop Go version
pkill -f lid-lock-daemonrm ~/.config/autostart/lid-lock.desktop- Check daemon is running:
ps aux | grep lid-lock-daemon - Check permissions:
ls -l ~/.local/bin/lid-lock-daemon.sh - Test lock manually:
gnome-screensaver-command -l
- Verify settings:
gsettings get org.gnome.settings-daemon.plugins.power lid-close-ac-action - Should return
'nothing'
The daemon monitors lid state via D-Bus (org.freedesktop.login1.Manager.LidClosed) every second. When it detects lid closing, it locks the screen. GNOME power settings are configured to do 'nothing' when lid closes, so the system never suspends.
Both versions provide the same functionality:
- Bash versions: Simple, no compilation needed, easy to modify
- Go versions: Better performance, single binary, easier to distribute
Choose based on your preference. The Go versions are recommended for production use due to better resource usage and performance.
- Linux with GNOME desktop environment
- systemd (most modern distributions)
- Tested on: Ubuntu 22.04+, Fedora, Debian with GNOME
For Go versions:
- Go 1.21 or later (for building from source)
- Or use pre-built binaries (if available)
- Screen locks when lid closes
- System stays powered on - configure firewall properly
- SSH access remains - use key-based authentication
- Consider full disk encryption for additional security
Free to use and modify as needed.
Feel free to submit issues or pull requests with improvements!
Created to solve the problem of keeping Linux laptops running while maintaining screen security.