Technology Insights

SSH Add Server To known_hosts Automatically

If you ever need to write a shell script that uses either SSH or SCP to unknown hosts then you will likely have run across the issue of adding the remote host/server to the known_hosts file when automating either of the two commands are called within the script. You can easily get around this either by modifying the client computers ssh_config file or by using the -o switch available for both SSH (Secure Shell) and SCP (Secure Copy). Below we show how to modify the ssh_config file as well as an example of using each with the -o switch.

Technology Insights

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

If you attempt to SSH to a server and receive a message similar to the below:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
23:43:66:2a:ac:53:d9:62:8c:af:03:5f:6b:67:b7:86.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:5
RSA host key for server.example.com has changed and you have requested strict checking.
Host key verification failed.
lost connection