Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 04-17-2008, 02:45 PM   #1
LQ Newbie
Registered: Jul 2007
Posts: 19

Rep: Reputation: 9
Question 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.

Old 04-17-2008, 06:30 PM   #2
Registered: May 2001
Posts: 29,361
Blog Entries: 55

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
search quick download tools linwenyuan Linux - Desktop 6 09-23-2006 12:29 PM
Level editing tools GameMaker Linux - Games 1 02-07-2006 05:27 PM
ssh known_hosts question lthaus Linux - Security 1 12-08-2004 10:07 PM
Audio Editing and Video capture tools... redrobin77 SUSE / openSUSE 2 11-25-2004 07:58 AM
Image Editing Tools Suggestions Please tiredoflogins Linux - Software 14 11-07-2004 12:46 PM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:57 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration