Skip to main content
added 219 characters in body
Source Link
Tino
  • 1.3k
  • 10
  • 12

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 tmux directly (not via systemd-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 

The missing bit can be found on SU:

First: Keep the $USER's SystemD instance running after logoff:

sudo loginctl enable-linger $USER 

Second: 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 tmux directly (not via systemd-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.

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 tmux directly (not via systemd-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 
better `ssh` compatibility
Source Link
Tino
  • 1.3k
  • 10
  • 12

The missing bit can be found on SU:

First: Keep the $USER's SystemD instance running after logoff:

sudo loginctl enable-linger $USER 

Second: 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 tmux directly (not via systemd-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.

The missing bit can be found on SU:

First: Keep the $USER's SystemD instance running after logoff:

sudo loginctl enable-linger $USER 

Second: 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 tmux directly (not via systemd-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 && 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.

The missing bit can be found on SU:

First: Keep the $USER's SystemD instance running after logoff:

sudo loginctl enable-linger $USER 

Second: 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 tmux directly (not via systemd-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.

Wrapper now works, too, when DBUS is not in charge
Source Link
Tino
  • 1.3k
  • 10
  • 12

The missing bit can be found on SU:

First: Keep the $USER's SystemD instance running after logoff:

sudo loginctl enable-linger $USER 

Second: 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 tmux directly (not via systemd-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 && 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.

The missing bit can be found on SU:

First: Keep the $USER's SystemD instance running after logoff:

sudo loginctl enable-linger $USER 

Second: 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 tmux directly (not via systemd-run), it get's killed.
  • Hence either use an alias or a wrapper script like follows:
#!/bin/bash [ -x /usr/bin/systemd-run ] && 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.

The missing bit can be found on SU:

First: Keep the $USER's SystemD instance running after logoff:

sudo loginctl enable-linger $USER 

Second: 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 tmux directly (not via systemd-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 && 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.

Source Link
Tino
  • 1.3k
  • 10
  • 12
Loading