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.)
tmux under control of the
$USER's SystemD instance:
systemd-run --scope --user tmux
There is no need to change
/etc/systemd/logind.conf for this.
- This is needed only for Users who are not
- If you start
tmux directly (not via
systemd-run), it get's killed.
- Hence either use an alias or a wrapper script like follows:
[ -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.
/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
Update 2: Reboot is needed and linger state can be found with
ls -al /var/lib/systemd/linger