【问题标题】:Problem with executing "ssh-add" or eval 'ssh-agent' using Chef使用 Chef 执行“ssh-add”或 eval 'ssh-agent' 的问题
【发布时间】:2019-12-18 18:19:08
【问题描述】:

我正在尝试使用 Chef 将私钥添加到 Amazon Linux 机器。密钥在 s3 中,我将其复制到目录中。然后我使用“eval ssh-agent”启动 ssh-agent。一切都很好,直到“ssh-add”部分=它错误“无法打开与您的身份验证代理的连接。”。所以看来 eval ssh-agent 没有启动。

execute "sudo aws s3 cp --region us-east-1 s3://xxxx/keyname ~/.ssh/keyname"
execute "eval `ssh-agent`" 
execute "ssh-add ~/.ssh/keyname" <--this is where it fails 

我已经确认钥匙在那里。我还尝试通过连接到盒子并运行命令来手动执行这些步骤 - 它可以工作。

但是当它在 CHEF 中时它会失败。

如果有帮助,这里是错误日志:

================================================================================
Error executing action `run` on resource 'execute[ssh-add ~/.ssh/keyname]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '2'
---- Begin output of ssh-add ~/.ssh/keyname ----
STDOUT: 
STDERR: Could not open a connection to your authentication agent.
---- End output of ssh-add ~/.ssh/keyname ----
Ran ssh-add ~/.ssh/keyname returned 2

我碰壁了,感谢您的帮助。

【问题讨论】:

    标签: amazon-web-services ssh chef-infra


    【解决方案1】:

    利用众所周知的食谱,例如users cookbook,它是从数据包中管理操作系统用户和组的。它还管理 ssh 密钥到用户主目录的分发。

    【讨论】:

      【解决方案2】:

      如果有人感兴趣,请按照以下步骤操作:

      所以我们添加密钥并将perm更改为600:

      execute "sudo aws s3 cp --region us-east-1 s3://priv /root/.ssh/priv"
      execute "sudo chmod 0600 /root/.ssh/priv"
      

      我们也复制 .ssh/config

      execute "sudo aws s3 cp --region us-east-1 s3://config
      execute "sudo chmod 0644 /root/.ssh/config"
      

      现在是时候使用了。

      ssh-agent bash -c 'ssh-add /root/.ssh/priv; git clone etc....
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-01-13
        • 2022-12-16
        • 1970-01-01
        • 1970-01-01
        • 2021-11-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多