Activating systemd --user for the first time
20 Jun 2023Whenever I set up a fresh linux machine I always struggle with activating systemd --user for the first time. Here are the steps:
This is not really a TIL. In the back of my head I have know that sudo su - or sudo su - someuser is not really the correct way to switch to another user. But I never took the time to remember the correct way. I promised myself to finally remember it from now on:
- (as root) enable lingering:
loginctl enable-linger $newuser - check if
UsePam yesis set in/etc/ssh/sshd_config - (as root)
echo $DBUS_SESSION_BUS_ADDRESS - (as $newUser) add
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$newUID/bus"to~/.bash_profile(copy path from the previous command and insert correct UID) - (as $newUser)
mkdir -p ~/.config/systemd/user
And lastly add the required services to .config/systemd/user, enable and run. (And remember: defaults.target is the right setting for [Install]/WantedBy because multi-user.target only exists on systems with a graphical frontend).