【问题标题】:Cannot connect via SSH from Github Action workflow无法通过 Github Action 工作流程中的 SSH 连接
【发布时间】:2021-03-27 00:57:54
【问题描述】:

Github Actions runner 通过 SSH 连接到创建的 Droplet。

我的步骤:

  1. ssh-keygen -t rsa -f ~/.ssh/KEY_NAME -P ""
  2. doctl compute ssh-key create KEY --public-key "CONTENT OF KEY_NAME.pub"
  3. doctl compute droplet create --image ubuntu-20-04-x64 --size s-1vcpu-1gb --region fra1 DROPLET_NAME --ssh-keys FINGERPRINT --wait
  4. ssh -vvv -i ~/.ssh/KEY_NAME root@DROPLET_IP

✔️ 使用从 cmd 运行的 doctl.exe 在 Windows 本地计算机上测试 - 有效!
✔️ 使用 doctl 脚​​本在基于 Linux 映像的 Docker(安装在 Windows 上)测试 - 有效!
⚠️ 使用 digitalocean/action-doctl 脚本在基于 ubuntu-latest 的 Github Actions 运行器上测试 - 不起作用!

收到的消息是:connect to host ADDRESS_IP port 22: Connection refused

所以步骤是正确的,为什么这对 Github Actions 不起作用?

【问题讨论】:

    标签: ssh digital-ocean github-actions ssh-keygen droplet


    【解决方案1】:

    如果您使用的是 GitHub Action digitalocean/action-doctl,请先检查 issue 14

    为了通过 SSH 连接到 Droplet,doctl 需要访问 SSH 密钥对的私有部分,其公共部分在 Droplet 上。
    目前,doctl Action 是基于 Docker 容器的。

    如果你直接使用 Docker 容器,你可以调用它:

    docker run --rm --interactive --tty \
     --env=DIGITALOCEAN_ACCESS_TOKEN=<YOUR-DO-API-TOKEN> \
     -v $HOME/.ssh/id_rsa:/root/.ssh/id_rsa \
     digitalocean/doctl compute ssh <DROPLET-ID>
    

    为了从容器外部挂载 SSH 密钥。

    您最好只使用doctl grep Droplet 的 IP 地址并使用这个更专注于 SSH 相关用例并提供许多附加功能的操作:marketplace/actions/ssh-remote-commands

    【讨论】:

      猜你喜欢
      • 2015-10-21
      • 2012-03-20
      • 2016-04-16
      • 2012-09-04
      • 2022-12-13
      • 2017-03-01
      • 2020-11-08
      • 2020-09-11
      相关资源
      最近更新 更多