Skip to main content

Remove Host ID

(2014-06-26)

Problem

Host-ID has changed and ssh is complaining about it.

Solution

Shell alias:

# edit the ~/.ssh/known_hosts file to remove the passed line number.
#  source: [https://chainsawonatireswing.com/2012/04/06/an-easier-quicker-way-to-edit-the-known_hosts-file-when-an-ssh-server-changes-its-host-key/
trim-ssh () {
  cp ~/.ssh/known_hosts ~/.ssh/known_hosts_$(date +%Y%m%d-%H%M%S) ;
  sed -e "$1d" ~/.ssh/known_hosts > ~/.ssh/known_hosts_new ;
  mv -f ~/.ssh/known_hosts_new ~/.ssh/known_hosts ;
  chmod 644 ~/.ssh/known_hosts
}

Usage

Remove line 12 in the ~/.ssh/known_hosts file?

> trim-ssh 12