automatically start screen upon ssh login
A simple screen -R
should do the trick.
To verify this, I added screen -R
to my .bash_profile on a remote server, logged in, detached from screen, and was dropped back to a normal shell prompt on the remote server. Verified with .bashrc as well. Subsequent logins yielded the expected result (re-attach to screen session).
screen -RR
will reattach to the first available session or create one if necessary.
I had issues with 40 cascading screen sessions being created with some of the solutions when starting a new window or screen session. I was able to eliminate the cascading screen and create a new session if one didn't exist with this:
if [ -z "$STY" ]; then screen -R; fi
It tests whether you're in a screen session and runs screen -R
if you aren't. Without the test you get the "Attaching from inside of screen?" warning from screen each time you create a new screen window.