我在 cloudformation 模板中设置了一个自动缩放组,用于启动单个 ec2 实例。在启动配置的用户数据部分中,我执行以下语句:
sudo -u ec2-user git clone https://github.com/...git
我必须以 ec2 用户身份运行此程序,而不是以 root 身份运行。在 cloud-init-output.log 中,我收到以下错误: “致命:无法访问‘https://github.com/...git/’:无法解析主机:github.com;名称或服务未知”
关于如何以 ec2-user 身份运行它,有什么建议吗?
最佳答案
您看到的错误消息是:
Could not resolve host: github.com; Name or service not known
这是一个网络连接问题。参见例如this相关的 Stack Overflow 答案。
您还提到:
I have to run this as an ec2-user, not as root.
但是,您还没有说明原因,而且一般来说,没有理由不使用 root 用户从 Github 克隆代码。
如果您必须以 ec2 用户身份运行命令,请尝试:
cd /home/ec2-user
su ec2-user -c "git clone https://github.com/...git"
如果您只需要 root 用户使用属于其他用户的私钥:
GIT_SSH_COMMAND="ssh -i /home/ec2-user/.ssh/id_rsa" git clone <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cea9a7ba8ea9a7baa6bbace0ada1a3" rel="noreferrer noopener nofollow">[email protected]</a>:....git
否则,只需以 root 用户身份通过 HTTPS 克隆代码即可正常工作(如果您解决了网络问题)。
关于linux - 无法在用户数据部分中 git clone 作为 ec2-user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54834580/