What's the easiest way to batch SSH into multiple devices and run commands?
Asked by
TechieNinja42
I'm trying to automate SSH access to around 100 brand new devices on my local network. I need to connect, accept the host key (security isn't a concern here), issue a command, and then move on to the next device. I've got their IP addresses in a CSV file. The traditional methods I've tried, like using PLINK, haven't worked outโparticularly piping 'yes' to it just hangs. I'm looking for a PowerShell script that can do this efficiently without the hassle of logging in manually to each device. Any suggestions?
Answers
You might want to try using SSH with the option `-o StrictHostKeyChecking=accept-new` or `-o StrictHostKeyChecking=no`. This should help you bypass the host key checks and let you connect without issues.
Reply to this answer
Consider using threads or jobs to run your connections in parallel. This could speed things up significantly!
Reply to this answer
Just remember, you donโt actually need to log in to get the key. You can connect and pipe in `echo y` to accept the key. Check your loop structure to make sure it isnโt hangingโtry running something like `echo y | plink -ssh user@device "exit";`
CodeMaster101: I tried both methods in a loop, and they still just hang. Itโs so frustrating!
Reply to this answer
Keep in mind that PLINK has a `-batch` option you can use. It might be the solution you need to avoid those annoying prompts.
Reply to this answer
Have you looked into using Posh-SSH? It might streamline the process for you.
Reply to this answer
Add your answer
Answers are reviewed before publication.
ScriptingWizard007: This is a good call! Honestly, forget about PuTTY and PLINK; theyโre pretty outdated at this point.