
If you've spent enough time around Linux servers and desktops, you already know one universal truth:
Linux never does exactly what you expect… especially when you don’t have root.
A few weeks ago, I found myself in a situation that’s probably familiar to anyone who works on shared servers, university machines, or restricted corporate environments:
My session kept going to sleep, killing long-running scripts, dropping SSH tunnels, freezing terminals—for absolutely no good reason.
To make things worse, I didn’t have sudo on this box.
No changing systemd settings, no tweaking /etc/systemd/logind.conf, and definitely no masking sleep targets.
So I went down the rabbit hole of how to keep a Linux machine awake without any superuser privileges.
Here’s the write-up of that journey—and yes, the final solution is surprisingly elegant.
The Problem: When the System Sleeps, Your Work Dies
My main issue: every 15 minutes of inactivity, the system would suspend the session.
Not the entire PC — just my user session. It didn't matter if I had background jobs running or SSH tunnels open; if I wasn’t interacting, the session was toast.
The machines were managed centrally, so root was a luxury I simply didn’t have.
What followed was a typical sysadmin debugging sequence:
- Angry at the stupidity
- Google.
- Try things that shouldn’t work.
- Try things that definitely shouldn't work.
- Accidentally discover the correct solution while reading some random docs if point 3 doesn’t already solve it
The Trick: systemd-inhibit (Works Without Root!)
While digging through the systemd documentation, I discovered something beautiful:
Non-root users can create inhibitor locks.
This means your normal user account can ask systemd:
“Please don’t put this session to sleep while this program is running.”
And systemd says:
“Okay. I respect that.”
All it takes is:
systemd-inhibit –what=handle-lid-switch:sleep –mode=block sleep infinity
This command runs a never-ending sleep process—
and while it runs, the system is forbidden to suspend.
You can even run it in the background:
$ nohup systemd-inhibit sleep infinity &
Want to verify it’s working?
$ systemd-inhibit –list
You’ll see your inhibitor lock listed like a VIP pass at a nightclub.
If You Have caffeinate, Even Better
Some Linux distros ship with a utility called caffeinate (similar to macOS).
It’s almost poetic:
$ caffeinate -di sleep infinity
This one also blocks sleep while the command runs.
Just leave it running as a background job and your session stays alive.
The Primitive but Always-Working Hack: Keepalive Script
If neither systemd-inhibit nor caffeinate exist, you can fall back to a caveman approach and still have the basic functionality of the Move Mouse Windows tool on Linux :):
#!/bin/bash
while true; do
echo "Still here: $(date)"
sleep 60
done
This prevents session idleness by emitting activity every minute.
Not elegant, but reliable.
Sometimes the caveman wins.
Why This Matters
Keeping a session awake might sound trivial, but for sysadmins, developers, pentesters, researchers, or anyone running long processes on managed machines, it’s a lifesaver.
You avoid:
- broken SSH tunnels
- silent failure of long-running scripts
- GUI sessions locking themselves
- losing tmux/screen sessions
- interrupted compiles or renders
- VPN disconnects
And you don’t need to bug IT or break policy.
Final Thoughts
What surprised me most is how simple the final solution was:
- No root
- No configuration changes
- No hacks
- No kernel tweaks
Just one systemd command used properly.
Sometimes Linux feels like an inscrutable labyrinth… and sometimes it gives you a quiet, elegant tool hiding in plain sight.
If you ever find yourself fighting unwanted auto-suspend on a machine you don’t control –
give systemd-inhibit a try.








