From 03ee250a928e664814b283b9a97f3e4b6b2af476 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Wed, 16 Aug 2023 12:32:13 +0530 Subject: [PATCH] Set password auth in 50-cloud-init.conf for CentOS and RHEL systems 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: https://github.com/canonical/cloud-init/issues/4335 Signed-off-by: Ani Sinha --- VMAccess/vmaccess.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/VMAccess/vmaccess.py b/VMAccess/vmaccess.py index e4557f986..5d4fa321e 100644 --- a/VMAccess/vmaccess.py +++ b/VMAccess/vmaccess.py @@ -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))