Skip to content

Commit

Permalink
Set password auth in 50-cloud-init.conf for CentOS and RHEL systems
Browse files Browse the repository at this point in the history
Azure 'reset password' feature overrides the /etc/ssh/sshd_config file and sets
the PasswordAuthentication to 'yes'. Unfortunately, cloud-init versions 22.3 and
newer sets 'PasswordAuthentication' to 'no' in the
/etc/ssh/sshd_config.d/50-cloud-init.conf which overrides the setting in
/etc/ssh/sshd_config file. VMAccess handles this for Ubuntu by setting
PasswordAuthentication to 'yes' additionally in /etc/ssh/sshd_config.d/50-cloud-init.conf
file. This change extends the same method to include CentOS and RHEL systems.

Fixes: canonical/cloud-init#4335

Signed-off-by: Ani Sinha <anisinha@redhat.com>
  • Loading branch information
ani-sinha committed Aug 16, 2023
1 parent c70df43 commit 03ee250
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions VMAccess/vmaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,12 @@ def _allow_password_auth():
_set_sshd_config(config, "PasswordAuthentication", "yes")
ext_utils.replace_file_with_contents_atomic(SshdConfigPath, "\n".join(config))

if isinstance(MyDistro, dist_utils.UbuntuDistro): #handle ubuntu 22.04 (sshd_config.d directory)
if isinstance(MyDistro, dist_utils.UbuntuDistro) or \ #handle ubuntu 22.04 (sshd_config.d directory)
isinstance(MyDistro, dist_utils.RedhatDistro) or \
isinstance(MyDistro, dist_utils.CentOSDistro):
cloudInitConfigPath = "/etc/ssh/sshd_config.d/50-cloud-init.conf"
config = ext_utils.get_file_contents(cloudInitConfigPath)
if config is not None: #other versions of ubuntu don't contain this file
if config is not None:
config = config.split("\n")
_set_sshd_config(config, "PasswordAuthentication", "yes")
ext_utils.replace_file_with_contents_atomic(cloudInitConfigPath, "\n".join(config))
Expand Down

0 comments on commit 03ee250

Please sign in to comment.