LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   SSH - known_hosts ... Quick editing tools available? (https://www.linuxquestions.org/questions/linux-networking-3/ssh-known_hosts-quick-editing-tools-available-636052/)

corrosivemisery 04-17-2008 01:45 PM

SSH - known_hosts ... Quick editing tools available?
 
I'm hitting up the LQ community with a question on how to simplify an annoyance.

Question is...are there any tools in existence command line or GUI that can allow you to quick edit your ~/.ssh/known_hosts file? I'd like something that perhaps lists the IP/URL and allows you to just click and delete or pass the IP/URL to a command line util for deletion.

It'd be handy to have for DHCP environments where the ip address/key pair frequently changes.

-Corr

unSpawn 04-17-2008 05:30 PM

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.


All times are GMT -5. The time now is 02:40 PM.