The missing bit can be found on SU:
First: Keep the $USER's SystemD instance running after logoff:
sudo loginctl enable-linger $USER Second: Reboot. (According to man loginctl this becomes effective on the next boot only.)
Third: Start tmux under control of the $USER's SystemD instance:
systemd-run --scope --user tmux That's it.
There is no need to change /etc/systemd/logind.conf for this.
Note:
- This is needed only for Users who are not
root. - If you start
tmuxdirectly (not viasystemd-run), it get's killed. - Hence either use an alias or a wrapper script like follows:
#!/bin/bash [ -x /usr/bin/systemd-run ] && dbus-send --print-reply / org.freedesktop.DBus.Peer.Ping && /usr/bin/systemd-run --scope --user -- /bin/true && exec /usr/bin/systemd-run --scope --user -- /usr/bin/tmux "$@" exec /usr/bin/tmux "$@" I install this with chmod +x "$HOME/bin/tmux" to avoid edits of .bashrc which might vanish if your profile is reset.
Update: /usr/bin/systemd-run --scope --user -- /bin/true is needed to test that systemd-run is usable in ssh context while X11 is active in parallel. Here, to run permanent tmux, you apparently need to run it from X11 session, not ssh.
Update 2: Reboot is needed and linger state can be found with
ls -al /var/lib/systemd/linger