Configure openhabian SSH to use "screen"

  • Platform information:
    • Raspberry Pi 3B
    • OS: Openhabian
    • openHAB version: 2.4.0-1 (Release Build)

I was having a lot of issues with SSH sessions timing out during things like software installation, or editing configuration files. When SSH times out, it appears near impossible to go back to where you left off. For example, if you are editing a file, and your SSH connection is closed for any reason, you cannot return to editing that file, you must start again.
Unless you use “screen”. Screen basically keeps your session going and allows you to reconnect to it.

I have configured my installation to always use screen when connecting via ssh. Doing this means I see where I left off and can continue on like nothing happened.

Note: your non screen bash command history will not transfer to the screen sessions, but screen does keep bash command history. I’m sure there must be a way to transfer it too, but I didn’t try.

Here’s what I did-

# Move the current SSH welcome message to new location:
This ensures the welcome message still displays when a new screen session is started. e.g. after reboot, or if you exit the screen session and start a new one.
It doesn’t get displayed for a session reconnection.

sudo mv .bash_profile .bashrc

# Use screen on SSH login:

sudo nano .bash_profile

Enter the following and save:

# Original .bash_profile moved to .bash_profile_OLD
# Start screen, reconnect to existing session if there is one.

screen -RR

# Set Screen to keep more history.
Allows you to scroll up a lot further

sudo nano ~/.screenrc

Enter the following and save:

defscrollback 100000
termcapinfo xterm ti@:te@

All Done
Now if you connect via SSH it should reconnect to the last session, if there is one, and you can continue from where you stopped last time.

If you ever need to close the session for any reason, type

exit

You should see the message [screen is terminating]

and to start a new session if you used exit

screen

Couple of notes @Andrew_Brake.
sudo mv .bash_profile .bashrc should be sudo mv .bash_profile .bash_profile_OLD
You also need to do a chown and chgrp for the new .bash_profile and .screenrc to fit the correct User and Group.
Cheers, Edward

I moved it to .bashrc because Screen runs .bashrc when it starts a new session.

You are possibly correct with the rest, I wouldn’t know, but I’ve had no permissions issues.

If you do as explained above, then I fear that performing the following maintenance tasks through openhabian-config will revert your edits:

  • 10 Apply Improvements
    • 12 Bash&Vim Settings

Just tested, it overwrites the .bash_profile which does stop screen being used, but that appears to be all.

In all honesty, I think this should be baked into Openhabian. Not having a resumable session has caused me so much trouble over the last couple of years.

I opened a ticket on Github:

Awesome, thanks.

Hopefully it gets picked up