Last active
October 13, 2022 16:00
-
-
Save ryot4/6a462fa247312c786ffcf5aebd3a2cea to your computer and use it in GitHub Desktop.
A simple wrapper for ssh-keygen command to manage known_hosts file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ssh_known_hosts() | |
{ | |
local cur prev | |
_get_comp_words_by_ref cur prev | |
COMPREPLY=($(compgen -W 'find forget list' -- "${cur}")) | |
} | |
complete -F _ssh_known_hosts ssh-known-hosts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
usage() | |
{ | |
echo "$(basename "$0") [-f known_hosts_file] {find|forget|list} {hostname|[hostname]:port}" | |
} | |
known_hosts_file="${HOME}/.ssh/known_hosts" | |
while getopts f:h option; do | |
case "${option}" in | |
f) | |
known_hosts_file="${OPTARG}" | |
;; | |
h) | |
usage | |
exit | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
if [ $# -eq 0 ]; then | |
echo 'no command specified' 1>&2 | |
exit 1 | |
fi | |
case "$1" in | |
find) | |
if [ -z "$2" ]; then | |
echo 'no hostname specified' 1>&2 | |
exit 1 | |
fi | |
ssh-keygen -f "${known_hosts_file}" -F "$2" | |
;; | |
forget) | |
if [ -z "$2" ]; then | |
echo 'no hostname specified' 1>&2 | |
exit 1 | |
fi | |
ssh-keygen -f "${known_hosts_file}" -R "$2" | |
;; | |
list) | |
cat "${known_hosts_file}" | |
;; | |
*) | |
echo "unknown command: $1" 1>&2 | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment