By default, a SSH session close in case of network disconnection, killing automatically any and all software currently running. This guide use the “byobu” software render SSH sessions persistent during disconnections.

This howto is tested on:

  • Debian 10.0 Buster

Settings

Provide the username for which SSH sessions are to be persistent:

username="remote-user"

Installation

Detect if sudo is available (“command” is used if not):

cmdProxy='command'
command type -f 'sudo' &>'/dev/null' && cmdProxy='sudo'

Fetch the chosen user home path:

userPath="$(command getent 'passwd' "${username}" | command cut -d':' -f6)"

Environment setup

Install the software’s requirements:

${cmdProxy} apt install 'byobu' 'vlock' 'sudo'

Setup

Enable persistent SSH sessions for the chosen user:

sudo -u "${username}" byobu-launcher-install

For additional security, setup the SSH session to be locked by a password after a 5 minutes inactivity:

sudo -u "${username}" tee -a "${userPath}/.byobu/.tmux.conf" \
  <<< 'set-option -g lock-command vlock
set-option -g lock-after-time 300'

The chosen user’s next SSH session will be persistent between network disconnections.

Thanks

Categories: Setup

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.