Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cloudinit/ssh_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ def extract_authorized_keys(username, sshd_cfg_file=DEF_SSHD_CFG):

except (IOError, OSError):
# Give up and use a default key filename
auth_key_fns.append(default_authorizedkeys_file)
auth_key_fns[0] = default_authorizedkeys_file
util.logexc(LOG, "Failed extracting 'AuthorizedKeysFile' in SSH "
"config from %r, using 'AuthorizedKeysFile' file "
"%r instead", DEF_SSHD_CFG, auth_key_fns[0])

# always store all the keys in the first file configured on sshd_config
return (auth_key_fns[0], parse_authorized_keys(auth_key_fns))
# always store all the keys in the user's private file
return (default_authorizedkeys_file, parse_authorized_keys(auth_key_fns))


def setup_user_keys(keys, username, options=None):
Expand Down
6 changes: 3 additions & 3 deletions tests/unittests/test_sshutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def test_multiple_authorizedkeys_file_order1(self, m_getpwnam):
fpw.pw_name, sshd_config)
content = ssh_util.update_authorized_keys(auth_key_entries, [])

self.assertEqual(authorized_keys, auth_key_fn)
self.assertEqual("%s/.ssh/authorized_keys" % fpw.pw_dir, auth_key_fn)
self.assertTrue(VALID_CONTENT['rsa'] in content)
self.assertTrue(VALID_CONTENT['dsa'] in content)

Expand All @@ -610,15 +610,15 @@ def test_multiple_authorizedkeys_file_order2(self, m_getpwnam):
sshd_config = self.tmp_path('sshd_config')
util.write_file(
sshd_config,
"AuthorizedKeysFile %s %s" % (user_keys, authorized_keys)
"AuthorizedKeysFile %s %s" % (authorized_keys, user_keys)
)

(auth_key_fn, auth_key_entries) = ssh_util.extract_authorized_keys(
fpw.pw_name, sshd_config
)
content = ssh_util.update_authorized_keys(auth_key_entries, [])

self.assertEqual(user_keys, auth_key_fn)
self.assertEqual("%s/.ssh/authorized_keys" % fpw.pw_dir, auth_key_fn)
self.assertTrue(VALID_CONTENT['rsa'] in content)
self.assertTrue(VALID_CONTENT['dsa'] in content)

Expand Down