Circumventing "Remote Host Identification Has Changed" warning
If you want to pass arguments to a something pre-defined in Bash, you could use a function instead of an alias to the same effect:
ssh-keyrm() { ssh-keygen -f "$HOME/.ssh/known_hosts" -R "$1"; }
Which would be run as such:
$ ssh-keyrm 127.0.0.1
Like aliases, functions can be stored in .bashrc, .bash_profile, or defined inlne in a shell.
you cannot provide an argument to alias
Bash aliases work as simple expansions (the alias name just gets replaced with the alias value), so they cannot reference individual arguments using $n.
However, you can provide arguments as long as they go at the end of the command. With an alias like this:
alias rmh="ssh-keygen -f ~/.ssh/known_hosts -R"
you can run it as rmh 192.168.0.1
and although the word rmh
will be expanded, all arguments following it will still remain in the same place.
I have a similar problem with different devices using the same IP, but took a slightly different approach to solve it: prevent the host keys from going in to known_hosts
in the first place.
alias sshn='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
Then run sshn
whenever you want to disable host key security.
$ sshn [email protected]
Warning: Permanently added '192.168.1.1' (ECDSA) to the list of known hosts.
[email protected]'s password:
ssh tells you it added the host to the known hosts, but it didn't actually since the write went to /dev/null
. You can suppress this by fiddling with the logging level, but that may turn off other useful messages.
I also have StrictHostKeyChecking=no
so that it skips the authenticity prompt, but if you'd prefer to see the key fingerprint, you can omit that option.