Skip to content

Instantly share code, notes, and snippets.

@HenryQW
Last active April 6, 2018 12:45
Show Gist options
  • Save HenryQW/4744aa4cb4ed36745168686a9c0b8360 to your computer and use it in GitHub Desktop.
Save HenryQW/4744aa4cb4ed36745168686a9c0b8360 to your computer and use it in GitHub Desktop.
ssh-keyscan
#!/bin/bash
if [ ! "${1}" ]
then
echo "Usage : ${0} TARGET_HOST"
exit 1
fi
TARGET_HOST="${1}"
KNOWN_HOSTS_FILE="${HOME}/.ssh/known_hosts"
if [ ! -f "${KNOWN_HOSTS_FILE}" ]
then
touch ${KNOWN_HOSTS_FILE}
chmod og-rwx ${KNOWN_HOSTS_FILE}
fi
echo "Remove existing fingerprint of ${1} if exists"
ssh-keygen -R ${1} 2>/dev/null
echo "Add fingerprint of ${1}"
ssh-keyscan ${TARGET_HOST} 2>/dev/null >> ${KNOWN_HOSTS_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment