How ti check if passwordless ssh is enabled between two systems

I am writing a script which will execute commands on remote host only if they have a passwordless ssh setup. How do i check for that in my script

Make a list of hosts which have it and search the list.

Place the following entry in the ~/.ssh/config

PasswordAuthentication no

Execute the script, if passwordless login is enabled then it will login and execute your script.

If not, then it will say the following error and exit...

Permission denied (publickey,password).

So it will not endlessly wait for the password prompt... and does the required thing faster ...

Hope the above helped. .. Let us know !

Actually I am writing a script which will be executed in client box. Of course i cannot change the security settings (related to ssh) in there box.
Using my script the client need to connect to another host only if it is a passwordless ssh authentication. Else i need to prompt my client to create passwordless ssh authentication with that host.
Can i do this without modifying his ssh config file?

This works for me:
ssh -o 'PreferredAuthentications=publickey' ${TARGET_USER}@${TARGET_SSH_HOSTNAME} "echo"

The (-o) option is a good way to temporarily override ssh_config/sshd_config settings as needed for a command-line sequence

The "echo" command is just something to run, which will exit immediately, replace it with something like 'hostname' if you really want to bulletproof your test so that hostname=$TARGET_SSH_HOSTNAME

ExitCode=0 (Success)
ExitCode=255 (Login failure)

You misunderstood :cool:

I have the feel that it is not possible to change in all the machines whereever you are trying to login !! And you need to edit the config file in your server ( the server from where you invoke your ssh), not in the client box. It is very much useful when you want to make this setting permanent.

I believe you would be able to do it once, in your machine !! Else the other solution that is suggested above !!