From 55b6101e1be79c5644941ed580d6fcd6d39df78e Mon Sep 17 00:00:00 2001 From: Noam Angel Date: Mon, 31 Oct 2016 11:23:33 +0200 Subject: [PATCH] add option to configure cloud-init to allow password authentication This patch will configure cloud-init to allow password authentication. This is usefull in case you use "devuser" element and want to ssh guest image. Change-Id: I00e38aa2753f26b4cdd34d0fd85fc8e0de78171f --- elements/cloud-init/README.rst | 9 ++++++++ .../21-cloud-init-allow-password-auth | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100755 elements/cloud-init/post-install.d/21-cloud-init-allow-password-auth diff --git a/elements/cloud-init/README.rst b/elements/cloud-init/README.rst index 3a1c8fef..e76e956b 100644 --- a/elements/cloud-init/README.rst +++ b/elements/cloud-init/README.rst @@ -6,3 +6,12 @@ Install's and enables cloud-init for systems that don't come with it pre-installed Currently only supports Gentoo. + +Environment Variables +--------------------- + +DIB_CLOUD_INIT_ALLOW_PASS_AUTH + :Required: No + :Default: password authentication disabled when cloud-init installed + :Description: customize cloud-init to allow ssh password + authentication. diff --git a/elements/cloud-init/post-install.d/21-cloud-init-allow-password-auth b/elements/cloud-init/post-install.d/21-cloud-init-allow-password-auth new file mode 100755 index 00000000..643653e2 --- /dev/null +++ b/elements/cloud-init/post-install.d/21-cloud-init-allow-password-auth @@ -0,0 +1,22 @@ +#!/bin/bash + +if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then + set -x +fi +set -eu +set -o pipefail + +# Set cloud-init to allow password authentication +if [ -n "${DIB_CLOUD_INIT_ALLOW_SSH_PWAUTH:-}" ]; then + if [ -f "/etc/cloud/cloud.cfg" ]; then + if [ -z "$(cat /etc/cloud/cloud.cfg | grep ssh_pwauth)" ]; then + echo "ssh_pwauth not exist. append to EOF" + sudo sh -c 'echo "ssh_pwauth: 1" >> /etc/cloud/cloud.cfg' + else + echo "ssh_pwauth exist. make sure ssh_pwauth enabled" + sed -i -e 's/ssh_pwauth: *0/ssh_pwauth: 1/g' /etc/cloud/cloud.cfg + sed -i -e 's/ssh_pwauth: *False/ssh_pwauth: True/g' /etc/cloud/cloud.cfg + sed -i -e 's/ssh_pwauth: *false/ssh_pwauth: true/g' /etc/cloud/cloud.cfg + fi + fi +fi