ssh fails 60 percent of the time Oo

I am creating a droplet like this : new_droplet=$(curl -X POST “
-H “Authorization: Bearer $DO_TOKEN”
-H “Content-Type: application/json”)

after extracting some item from the JSON I am using the following to move a folder and substructure to the droplet:

tar -vczf - * | ssh -o StrictHostKeyChecking=accept-new root@${new_droplet_ip} tar -xzf - -C /opt/

it starts listing files and then stops. 30 percent of the time it announces that the key has been added to known hosts. and proceeds through the rest of the script

the rest of the time it returns ssh: connect to host IP address here port 22: Connection refused tar: -: Wrote only 4096 of 10240 bytes tar: Child returned status 141 tar: Error is not recoverable: exiting now

the ssh takes (15 seconds? ish )to respond, I suspect sometimes it’s longer and times out?

comments and suggestions appreciated


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello, @jefftully

Are you experiencing the same ssh-timeouts when you’re connected with an ssh-client like Putty or using your terminal?

I will recommend you to check our existing tutorial on how to troubleshoot the connection refused errors in ssh:

Hope that this helps! Regards, Alex