Skip to content

Commit

Permalink
add IP address entries also to known-hosts file
Browse files Browse the repository at this point in the history
  • Loading branch information
rikukissa committed Feb 7, 2024
1 parent a12177e commit febaa0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion infrastructure/environments/update-known-hosts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ if [ "$#" -ne 1 ]; then
fi

DOMAIN=$1
IP=$(dig +short $DOMAIN)
KNOWN_HOSTS_FILE="infrastructure/known-hosts"

# Ensure the known-hosts file exist
touch "$KNOWN_HOSTS_FILE"

# Remove existing entry for the domain from the known-hosts file
ssh-keygen -R "$DOMAIN" -f "$KNOWN_HOSTS_FILE" || true
ssh-keygen -R "$IP" -f "$KNOWN_HOSTS_FILE" || true

# Initialize keyscan result variable
KEYSCAN_RESULT=""

# Attempt to fetch the new SSH public key for the domain
while [ -z "$KEYSCAN_RESULT" ]; do
# Use `|| true` to prevent script exit if ssh-keyscan fails
KEYSCAN_RESULT=$(ssh-keyscan "$DOMAIN" 2>/dev/null) || true
KEYSCAN_RESULT=$(ssh-keyscan "$DOMAIN" "$IP" 2>/dev/null) || true

# Check if ssh-keyscan was successful
if [ -z "$KEYSCAN_RESULT" ]; then
Expand Down
3 changes: 3 additions & 0 deletions infrastructure/known-hosts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ farajaland-qa.opencrvs.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGSIBuxNbsqj+NYkQ
farajaland-dev.opencrvs.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHZVo8Jsqw6akzCRm8ID0zd2OAxU5NeOvS/iE3win98w
farajaland-dev.opencrvs.org ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDWFbOMgypl/mCjtTbnYQl4CRMxV/pp/7FupLnVnabFFeBv5OECrFTku3zV1n2hmbQZNJdO3gREQeV67olSBg554wp8CLJoE2l0SV1Gg56zz58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q89Q31hOWnilbgEJbb5u+l+aeEK/MKeo2Epx0SZckLwo3YmL6vM00ykIzqrS3ERw/K1GGSmZtBIplDALJWLt0OZR3vwnktR/4oj6+Iy1PuIa9i+bw0OVo8ScolgRHxZok8=
104.248.36.17 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBC6FQAe/NJr47AbOwedQoK9+pIgaiBte1c66fLTSsNnWiBEvte4JL4ar+DHtbjhE8Huzui+Bn9U/JFo/VzgTWzQ=

0 comments on commit febaa0e

Please sign in to comment.