Skip to content
HackIndex logo

HackIndex

SSH Key-Based Authentication Testing

2 min read Jan 3, 2026

Test key-based access cleanly, without your client spamming every identity and tripping server-side auth limits.

Confirm the server will even accept publickey

If publickey isn’t offered, stop. Key testing is wasted effort.

┌──(kali㉿kali)-[~]
└─$ ssh -vvv -p $PORT -o BatchMode=yes -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $USERNAME@$TARGET_IP exit

If you see publickey in the “can continue” line, the branch is open.

Test a known private key

Use the key directly and keep it tight.

┌──(kali㉿kali)-[~]
└─$ ssh -p $PORT -i id_rsa $USERNAME@$TARGET_IP

If you want a fast fail without prompts:

┌──(kali㉿kali)-[~]
└─$ ssh -p $PORT -i id_rsa -o BatchMode=yes $USERNAME@$TARGET_IP exit
Permission denied (publickey).

That means the key was offered and rejected.

Avoid “Too many authentication failures”

If you have many keys loaded, OpenSSH will try several identities. Some servers drop you before it tries the right one.

┌──(kali㉿kali)-[~]
└─$ ssh -p $PORT -i id_rsa -o IdentitiesOnly=yes $USERNAME@$TARGET_IP

If you’re still getting dropped, run verbose and watch which keys the client offers:

┌──(kali㉿kali)-[~]
└─$ ssh -vvv -p $PORT -i id_rsa -o IdentitiesOnly=yes $USERNAME@$TARGET_IP

References