Last active
April 6, 2018 12:45
-
-
Save HenryQW/4744aa4cb4ed36745168686a9c0b8360 to your computer and use it in GitHub Desktop.
ssh-keyscan
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/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