ssh – remove offending key.
2016-04-04
192 words
1 min read
Whenever a system/server is re-installed or the host key changed for any reason, you would have seen the “host key verification failed”. And as usual you would have to go to known_hosts file and delete the offending key. I will show you 2 simple ways to do this here.
The output that you get in such scenario is:
Offending ECDSA key in ~/.ssh/known_hosts:4
First, you can use sed to directly delete the offending key with a command like this :
sed -i 4d ~/.ssh/known_hosts
So, if you see, we are using “-i” to do the changes inline and using “4d” command to delete the 4th line.
But being on Linux has the advantage that everything can be automated. So, lets do this in simpler way.
We will be using command called xclip for this, so get that intalled.
sudo dnf install xclip
Once that is done, add a alias in your bashrc file like this:
alias ssh-remove-key='a=( $(xclip -o|sed "s,:, ,") ) ; sed -i -e "${a[1]}d" ${a[0]}'
After this is done, whenever you get that error, copy the “
Related Articles:
- 2016/02/15 DNS – simple and effective guide with history
- 2015/09/21 Executing commands on multiple hosts
- 2015/03/04 ssh authorized keys – limit ssh session to custom command
- 2014/10/24 Multiple entry in .ssh/config file
- 2014/09/01 Debuggging bash cron scripts.
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.