使用 CloudFormation 自动创建 linux 用户密码

Creating linux user password automatically with CloudFormation

我正在使用 CloudFormation 创建一个 EC2 Linux 机器,我可以通过 RDP 将其连接到其中。我是 运行 所需的安装命令:

"Metadata" : {
            "AWS::CloudFormation::Init" : {
                "config" : {
                    "commands" : {
                        "step_a" : {
                             "command" : "install some stuff..."
                        },
                        "step_g" : {
                            "command" : "sudo yum groupinstall \"Gnome Desktop\" -y"
                        },
                        "step_h" : {
                            "command" : "sudo passwd centos"
                        },
                        "step_i" : {
                            "command" : "configure firewall to allow rdp..."
                        }
                    }
                }
            }
        }

如你所见,在 step_h 中,我想为默认的 centos 用户设置密码。当需要用户输入时,如何自动 return 默认密码值?也许有更好的方法来解决这个问题?

如有任何帮助,我们将不胜感激!

有几种方法可以在没有提示的情况下设置用户密码。其中一些可以找到 here or here 作为示例。

但是,需要考虑的潜在问题是您将如何在模板中提供此密码?用纯文本硬编码?这是安全问题。使用 NoEcho 将其作为模板参数传递?这更好但不可重现并且容易出错。使用 SSM 参数存储或 AWS Secretes Manager?这可能是最佳选择,但需要额外设置。