What’s the easiest way to batch SSH into multiple devices and run commands?

0
14
Asked By TechieNinja42 On

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?

5 Answers

Answered By TheCloudinator On

Have you looked into using Posh-SSH? It might streamline the process for you.

Answered By NetworkingPro On

Keep in mind that PLINK has a `-batch` option you can use. It might be the solution you need to avoid those annoying prompts.

Answered By PowerShellPal On

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!

Answered By DevOpsDweller On

Consider using threads or jobs to run your connections in parallel. This could speed things up significantly!

Answered By CodeGuru88 On

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.

ScriptingWizard007 -

This is a good call! Honestly, forget about PuTTY and PLINK; they’re pretty outdated at this point.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.