tmate-io / tmate

Instant Terminal Sharing
https://tmate.io/
Other
5.68k stars 302 forks source link

How to set up unattended session to headless computer? #247

Open jerkstorecaller opened 3 years ago

jerkstorecaller commented 3 years ago

I have the following situation.

1) Headless Debian 10 system on my home LAN, let's call it Target. It's on 24/7. It has the latest static binary of tmate. This is the PC I want to connect to. 2) Desktop computer on the same LAN as Target, let's called it LocalPC. This system can ssh to Target to initialize it/launch tmate, but I gotta be able to turn it off when I'm not using it. 3) Remote computer that wants to ssh to the Target at any time, let's call it RemotePC

On LocalPC, I open an SSH session to Target, and launch tmate -F. It prints out all the connection info, and i can then ssh from RemotePC to Target.

However, when I shut down LocalPC, or really just close the ssh connection between LocalPC and Target, RemotePC is no longer able to connect to Target. I get "[server exited] Connection to nyc1.tmate.io closed by remote host."

I also tried running "tmate -F &" in the LocalPC-to-Target ssh session, which I hoped would keep it running in the background. When I disconnect/reconnect this ssh session, I see tmate -F running in the background in ps aux, but TargetPC still can't ssh after the initial closing.

It seems like I have to keep open the ssh session that launched tmate in order to keep using it. How do I do this?

Swiftzn commented 3 years ago

This would be great. I see there is a way to launch a headless session with the below, and as long as you don't use exit when closing your session it does persist. tmate -S /tmp/tmate.sock new-session -d

Though having a similar option for -F would be amazing

beikeland commented 3 years ago

could variations of nohup tmate -F be what you're after? can close the ssh session without tmate being terminated.

>tmate.out ; nohup tmate -F > tmate.out & tail -f tmate.out clears the output, starts tmate and prints the new output as it becomes available. ctrl + c only terminates tail, and closing the ssh session leaves tmate running

edit: nohup tmate -F | cat - & was shorter and might also work