Operating System - HP-UX
1826172 Members
2260 Online
109691 Solutions
New Discussion

Re: Checking ssh authentication in a script

 
SOLVED
Go to solution
Tony Walker_2
Frequent Advisor

Checking ssh authentication in a script

I'm writing a script which will ssh to our various machines and perform some automated tasks. There are some machines however that do not yet have key authentication set up and as such when I run the ssh command it asks for a password and waits. How can I check for and ignore this behaviour and move onto the next server?

Thanks,

Tony
5 REPLIES 5
Charlie Rubeor
Frequent Advisor

Re: Checking ssh authentication in a script

I get around this issue by looking in the authorized_keys file. Before performing the ssh command, I execute the following:

grep root@ /.ssh/authorized_keys

That does not quarantee that the authorized key will be up to date, but it's the closest I could come up with. If you come across a better solution, please let me know!
RAC_1
Honored Contributor

Re: Checking ssh authentication in a script

In this case you will need to use expect tool. What this tool does is lloks at "prompts" and keys in things that you want.

There docs about this tool and easy to to understand.

Anil
There is no substitute to HARDWORK
Sridhar Bhaskarla
Honored Contributor
Solution

Re: Checking ssh authentication in a script

Tony,

You could try forcing the options like this

ssh -o "PreferredAuthentications publickey" -o "StrictHostKeyChecking no" $i "your command"


-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Florian Heigl (new acc)
Honored Contributor

Re: Checking ssh authentication in a script

Sridhar, this was *very* helpfull - I had always tried with passwordauthentication no, but without success.
Thanks a lot to You :)
yesterday I stood at the edge. Today I'm one step ahead.
Tony Walker_2
Frequent Advisor

Re: Checking ssh authentication in a script

Thankyou all. Sridhar - your suggestion worked perfectly.