Skip to content

Commit 362a621

Browse files
Rexlukeseawalker
authored andcommitted
Fix IP ssh key issue
* Adding IP with the same key mapping as hostname to known_hosts file * Add code to remove key when instance teminates * This will fix inconsistent key issue when user logs in compute with IP address Signed-off-by: Rex <[email protected]>
1 parent 8caa3f1 commit 362a621

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/common/ssh_keyscan.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _add_keys_to_known_hosts(server_keys, host_keys_file):
8686
key = RSAKey(data=base64.b64decode(key_tuple[0]))
8787
host_keys.add(hostname=hostname, key=key, keytype=key_tuple[1])
8888
host_keys.add(hostname=hostname + ".*", key=key, keytype=key_tuple[1])
89+
host_keys.add(hostname=socket.gethostbyname(hostname), key=key, keytype=key_tuple[1])
8990
logging.info(
9091
"Adding keys to known hosts file '{0}' for host '{1}'".format(host_keys_file, hostname)
9192
)
@@ -104,6 +105,8 @@ def _remove_keys_from_known_hosts(hostnames, host_keys_file, user):
104105
run_command(command, raise_on_error=False, execute_as_user=user)
105106
command = "ssh-keygen -R " + hostname + ". -f " + host_keys_file
106107
run_command(command, raise_on_error=False, execute_as_user=user)
108+
command = "ssh-keygen -R " + socket.gethostbyname(hostname) + " -f " + host_keys_file
109+
run_command(command, raise_on_error=False, execute_as_user=user)
107110

108111

109112
def update_ssh_known_hosts(events, user):

0 commit comments

Comments
 (0)