I'm a beginner Linux user, running Pop!_OS.

Pop!_OS is based on Ubuntu, but uses SystemD and Gnome. I have no idea if that's going to be relevant, but figured it wouldn't hurt to mention.

Here is what I'm attempting to accomplish:

1). After the screen is locked, set a timer for 30 minutes.

2). After the timer is expired, proceed with the shutdown.

3). If the screen is unlocked before timer expiration, cancel the shutdown.

I learned how to create a bash script, and tried this as an experiment:


gnome-screensaver-command --lock

shutdown -r +2

It locked me out of my computer for two minutes before rebooting. I was unable to unlock the screen, open the terminal, and enter shutdown -c, to cancel shutdown.

It displayed this message on the lock screen:

"System is going down. Unprivileged users are not permitted to login anymore. For technical details, see pam_nologin(8)."

I don't want to make myself the root user.

The closest thing on the internet that I could find was this thread on Stack Exchange:

Lock system after awake suspend (incl. forced-shutdowns system after countdown)?

I have no idea what's meant by "X terminal", or a "virtual terminal", so I have no idea if that's applicable. I've already locked myself out of my computer once, so now I'm asking for help.

Basically, sort of like a "suspend, then hibernate", I'm trying to do a "lock, then shutdown", if that makes sense.

Thank you in advance for your advice.

  • The only way that comes to mind is to use something like systemd-lock-handler. I don't know if it's still maintained or if it works but worth trying. Install it per the instructions, create a user unit to test ... your unit should contain something like ExecStartPre=120 (that's a 2 minutes delay) and ExecStart=/usr/bin/systemctl poweroff ... in theory it will be started on screen lock and stopped on unlock... Well, at least from the description it looks promising... Jan 3, 2023 at 0:06
  • actually I meant "something like ExecStartPre=/usr/bin/sleep 120" (that would be executed before the poweroff command in ExecStart...) Another way would be to monitor dbus for the lock/unlock session events (that's probably what systemd-lock-handler does underneath though I haven't looked at the source code) and have a script that does what you want (starts/cancels the counter etc) when those events are detected. Jan 3, 2023 at 15:44

1 Answer 1


Not exactly what you're looking for, perhaps but it should work:

Edit /etc/systemd/logind.conf this way:


Reboot. You're all set.

  • I've previously edited the logind.conf with those exact lines, the drawback here is that any user input (mouse, keyboard), will reset the "IdleActionSec" back to zero, because it's based on the duration of idle time, not the duration of the lock screen.
    – user555062
    Jan 2, 2023 at 4:55

You must log in to answer this question.