brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: loginctl enable-linger keeps your systemd user services running after you log out

Systemd
~/tips/tip-linux-loginctl-enable-linger

sudo loginctl enable-linger alice

Lets systemd user services start at boot and keep running when you are not logged in.

User services in systemd are great, right up to the moment you log out of SSH and they stop. On a server that is rarely what I want.

By default your user manager only lives while you have a session. Lingering changes that:

sudo loginctl enable-linger alice

The systemd docs put it like this: with lingering on, a user manager is spawned for the user at boot and kept around after logouts. So a systemctl --user service with WantedBy=default.target starts at boot and keeps running with nobody logged in. A personal sync job or a small app you run as your own user are good examples.

Without a user name it works on your own account, so loginctl enable-linger on its own is fine too. To undo it:

sudo loginctl disable-linger alice

loginctl show-user alice prints the properties of that user, and I’d look there to confirm it took effect.

Caveat: the man page points to KillUserProcesses= in logind.conf, which decides whether processes from a closed session get killed. Lingering keeps the user manager and its services alive; something you started by hand in a shell is a different story. For long jobs I’d make a proper user service instead of trusting a stray background process. These commands date from systemd 233, so any current distro has them.

Further reading: loginctl manual, On this site: timedatectl shows whether your server clock is in sync

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link