0

To login without password, I use ssh-copy-id I ~/.ssh/key_name root@server_ip.

If I don't copy my public key, then each time I use ssh root@server_ip I would be asked for my password.

Now I want to create an automated script for checking the installation of Ubuntu instances of our colleagues.

I want to know whether they have configured their Ubuntu correctly or not.

One item I should check is to see if they have copied their public keys to our server, so that they can connect without password.

How can I know it? Is there a way for me to know it?

2
  • @user68186, we're using Ubuntu 22.04 for clients, and Debian bullseye 11 for our servers. Nov 27, 2022 at 14:01
  • I tried the answer by @pLumo. It works for me.
    – user68186
    Nov 28, 2022 at 23:32

1 Answer 1

1

Just try ...

if ssh -o IdentitiesOnly=yes -o BatchMode=yes -i ~/.ssh/key_name -q user@host exit; then
    echo "Connection succesful"
else
    echo "Connection not succesful"
fi
  • -o IdentitiesOnly=yes means that, only the give key is checked
  • -o BatchMode=yes tells ssh not to fall back to a password prompt.
  • -q make ssh not output anything.
  • exit will let the connection quit immediately
2
  • Thank you for this script. However, when I run it, it freezes in the first line. Nov 24, 2022 at 9:09
  • @user68186, yep, I did not copy/paste blindly. I read and understood the code and replaced the parameters. Nov 27, 2022 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .