|
Guides All Guides and HOWTO's. |
|
Thread Tools | Display Modes |
|
|||
Remove host key from .ssh/known_hosts file
While I was playing with the OpenBSD autoinstall(8) and reinstalled a couple of OpenBSD virtual machines a few times, I decided to do something about the following:
Code:
Normally I would something like Code:
I came up with a shell script called rm-known_hosts-key that does the same work : Code:
Code:
Code:
#!/bin/sh # j65nko - daemonforums.org # ISC license # # remove key from .ssh/known_hosts by line number # --- verify numeric argument/option nr=$(expr "$1" : '\([0-9][0-9]*$\)' ) if [ -z "$nr" ] ; then echo $0: echo Please specify a line number ... exit 1 fi FILE="${HOME}/.ssh/known_hosts" #HOME=/root # for testing error condition # -- see mktemp(1) printf "$0: Creating temp file : " TEMP=$(env TMPDIR=${HOME} mktemp) || { echo $0: Cannot create temp file ; exit 2 } echo ${TEMP} ls -l ${TEMP} cat <<END Showing line nr $1 ...... $(sed -ne "$1p" ${FILE}) Using sed(1) to copy all lines except line $1 to ${TEMP} ... $(sed -e "$1d" ${FILE} > ${TEMP}) Moving ${TEMP} to ${FILE} ... END # for testing error condition #HOME=/root #FILE="${HOME}/.ssh/known_hosts" mv ${TEMP} ${FILE} || { echo $0: could not move ${TEMP} to ${FILE} ! exit 3 } # --- end of script --- Another improvement could be to remove the temp file when an error occurs.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump Last edited by J65nko; 21st December 2014 at 02:55 PM. Reason: Line number coloured in blue |
Tags |
.ssh/known_hosts, known_hosts, ssh host key, ssh host key change |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to remove a word and everything after? | bigb89 | Programming | 7 | 31st August 2014 01:47 AM |
How total remove .core file during a dump? | aleunix | OpenBSD Packages and Ports | 3 | 20th May 2012 06:38 PM |
How to remove Gnome and X | Malakim | Solaris | 2 | 12th April 2009 12:10 PM |
Appending to file on remote host via SSH | splooge | Programming | 10 | 7th June 2008 10:23 PM |