I'm connecting to a lot of devices that uses the same IP addresses. When I'm plugging them into the router I'm getting the warning message REMOTE HOST IDENTIFICATION HAS CHANGED!
and need to run ssh-keygen -f "/home/xxx/.ssh/known_hosts" -R "xx.xx.xx.xx"
if I still want to connect with the remote host.
My current strategy:
- I want to create a shortened command from:
ssh-keygen -f "/home/xxx/.ssh/known_hosts" -R "xx.xx.xx.xx"
- You can do it from any user.
- It should be a single command. (So I can copy paste a single line into other terminals in case I have not set it up in
.bash_profile
. - The
xx.xx.xx.xx
needs to be configurable.
Since you cannot provide an argument to alias (at least I think so) I tried solving it with read
:
$ alias ssh-keyrm='read LAST_SSH_IP_ADDRESS_CLEARED && ssh-keygen -f "$HOME/.ssh/known_hosts" -R "$LAST_SSH_IP_ADDRESS_CLEARED"'
$ ssh-keyrm
xx.xx.xx.xx
Any advice on how I can optimize it further?