I know how to enable/disable lingering with loginctl.
But up to now I found no way to query the status of a user.
I want to know: Is lingering enable for user foo?
How can I access this information?
You can show a list of lingering users with
ls /var/lib/systemd/linger
because
loginctl enable-linger $USER
loginctl disable-linger $USER
do the equivalent of
touch /var/lib/systemd/linger/$USER
rm /var/lib/systemd/linger/$USER
loginctl user-status foo shows linger status.
The best I found for check it in scripts (programmatically):
loginctl show-user "$USER" --property=Linger | grep -q 'yes'
loginctl show-user doesn't show me any property that has the word "linger" in it. And loginctl user-status shows me the linger status at the top, but does not support --property= for filtering. But the ls answer works, so looks like that's what I'll have to use.
– Cliff
Jun 29 '22 at 03:11
loginctl show-user and loginctl show-user $USER give completely different outputs. The latter shows Linger.
– chutz
Dec 29 '22 at 05:51
loginctl enable-linger otheruser then the show-user command no longer fails)
– hlovdal
Sep 28 '23 at 12:55
/var/lib/systemd/lingerdoes not exist until you « linger » your first user – Jocelyn delalande May 18 '20 at 14:48