josephchrzempiec
Posts: 163
Joined: Tue Jun 21, 2016 7:56 am

losing SSH

Sat May 18, 2019 2:40 am

Hello i have a question I was working on something in SSH but one time i lost the ssh connection and don't remember where i left off and i had to start all over again. I thought i saw a way to go back in and pick up where i left off in the terminal something called screen not sure the name of it can someone please help me out? I try to search for it and all I'm coming up with is LCD and Led screens. So I'm typing something wrong.



Joseph

tpyo kingg
Posts: 627
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: losing SSH

Sat May 18, 2019 3:28 am

That program would be GNU Screen. An easyshort cut is "screen -dR" which will connect to an old session if it is there or make a new session if there is none already running. "screen -ls" will show if you have any screen sessions running. You can maintain your connection with key-based authentication and a while loop, if it breaks such as may happen from a moving train or when you switch networks, say from home to school or work or a cafe.

Code: Select all

while ! ssh -t -i some.key.ed25519 -l pi xx.yy.zz.aa 'screen -dR'; do
        sleep 2;
done;
However, if you are just starting out, I'd recommend tmux instead. In many ways it is simpler to use. I moved from screen to tmux not so gradually for that reason.

Code: Select all

while ! ssh -t -i some.key.ed25519 -l pi xx.yy.zz.aa 'tmux attach-session || tmux new-session'; do
        sleep 2;
done;
There are a lot of guides and tutorials for both, but you can do a lot with just a small handful of options.

josephchrzempiec
Posts: 163
Joined: Tue Jun 21, 2016 7:56 am

Re: losing SSH

Sat May 18, 2019 3:45 am

Hello thank you. I'm not sure how to install screen? Is there commands for it? That is what i'm having a hard time installing.

tpyo kingg
Posts: 627
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: losing SSH

Sat May 18, 2019 3:51 am

Assuming the machine is headless, the generic answer is:

Code: Select all

sudo apt-get update;
sudo apt-get install tmux;
sudo apt-get install screen;
You can use either or both. Again, I'd recommend tmux. Read up on them a little and then try them.

Edit: along the same lines you can search for programs to install:

Code: Select all

apt-cache search screen;

josephchrzempiec
Posts: 163
Joined: Tue Jun 21, 2016 7:56 am

Re: losing SSH

Sat May 18, 2019 3:54 am

Thank you.

I forgot to ask what is tmux?

tpyo kingg
Posts: 627
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: losing SSH

Sat May 18, 2019 4:27 am

tmux is another terminal multiplexer, similar to screen. I have been a long time screen user but gravitated quickly to tmux after trying it out, thus multiple suggestions to take a look at it too.


Donna25
Posts: 1
Joined: Mon Mar 18, 2019 9:49 am

Re: losing SSH

Sat May 18, 2019 10:23 am

Yes tmux can be useful in this case,it is almost same to screen..Try it once,u will not get disappointed myschoolbucks

Return to “General discussion”