auto add ssh fingerprint without prompt

How to ssh: automatically accept keys

We can use following command to add fingerprint of a server to our known_hosts file.

ssh-keyscan -p<port> -H <ip-address> >> ~/.ssh/known_hosts
ssh-keyscan -p<port> -H <hostname> >> ~/.ssh/known_hosts

NOTE: We need to replace <port> <ip-address> and <hostname> with respective ssh port, IP and dns name of the server we want to add in known_hosts file.

This will allow us to enter Yes everytime connecting different servers.

In order to add a list of servers automatically we can do below:

Add servers IP in file servers-list

The IPs should be added in below format.

cat servers-list

123.1.2.3
124.1.2.4
123.1.2.5

Change above IPs by replacing yours.

Below command will add all servers from the list.

ssh-keyscan -p61 -H “`cat servers-list`” >> ~/.ssh/known_hosts

 

Thats all for now 🙂

Leave a Reply

Your email address will not be published.


*