Friday, 22 May 2020

How to ssh in a shell script




How to make ssh seamless for linux shell scripts





Sometimes we have trouble running ssh via shell script which loops through a huge list of hosts with key authorization and we face many issues like below :


  • a host is highly loaded that holds the session
  • host is not reachable
  • prompting for password 
  • you want to make ssh fail rather than prompt for password if the public key authorization fails 
  • prompting for typing 'yes/no' 


Solution which takes care of the everything above :

ssh -oBatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ConnectTimeout=5 -o PasswordAuthentication=no username@<hostname> "Do Stuff" 






No comments:

Post a Comment