Code:
function ssh_knownhosts_cfg() { # Edit your ~/.ssh/known_hosts
function __opsEnabled() { # Work on enabled hosts
enabled=`awk -F' |,' '/^[0-9,a-z,A-Z]/ {print $1}' .ssh/known_hosts`
select host in menu $enabled ; do [ "$host" == "menu" ] && break
echo "sed -i \"s|$host|#$host|g\" ~/.ssh/known_hosts"; break
done; } # end __opsEnabled
function __opsDisabled() { # Work on disabled hosts
disabled=`awk -F' |,' '/^#/ {print $1}' .ssh/known_hosts`
select host in menu $disabled ; do [ "$host" == "menu" ] && break
echo "sed -i \"s|$host|${host#\#}|g\" ~/.ssh/known_hosts"; break
done; } # end __opsDisabled
select type in enabled disabled quit; do
case "$type" in enabled) __opsEnabled;; disabled) __opsDisabled;;
quit) return 0;; esac; echo -en "1) enabled\n2) disabled\n3) quit\n"
done; } # end ssh_knownhosts_cfg
- This kludge works only with shells that can handle it and if your known_hosts is at ~/.ssh/known_hosts.
- This can only disable enabled hosts and enable disabled hosts.
- This should cover host lines with and without options.
- Check if my 'awk' and 'sed' needs improvement.
- Remove the echo and escapes from the sed lines.
- Add to your ~/.bashrc (or source a separate alias library, I do).
- Backup your ~/.ssh/known_hosts and don't tell me I didn't warn you.
- Type 'ssh_knownhosts_cfg' to run it.
- If it nukes your known_hosts file or your box you keep the fallout.