ssh - 无法通过 Github Action 工作流程中的 SSH 连接
问题描述
Github Actions runner 通过 SSH 连接到创建的 Droplet。
我的步骤:
ssh-keygen -t rsa -f ~/.ssh/KEY_NAME -P ""
doctl compute ssh-key create KEY --public-key "CONTENT OF KEY_NAME.pub"
doctl compute droplet create --image ubuntu-20-04-x64 --size s-1vcpu-1gb --region fra1 DROPLET_NAME --ssh-keys FINGERPRINT --wait
ssh -vvv -i ~/.ssh/KEY_NAME root@DROPLET_IP
✔️ 在 Windows 本地机器上使用 runned from 测试doctl.exe
-cmd
有效!
✔️ 使用脚本在基于 Linux 映像的 Docker(安装在 Windows)上测试doctl
- 有效!
⚠️ 基于 ubuntu-latest 使用digitalocean/action-doctl
脚本在 Github Actions 运行器上测试 - 不起作用!
收到的消息是:connect to host ADDRESS_IP port 22: Connection refused
。
所以步骤是正确的,为什么这对 Github Actions 不起作用?
解决方案
如果您使用的是 GitHub Action digitalocean/action-doctl,请先查看问题 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
.
推荐阅读
- json - 将 JSON 文件转换为 TFRecord 时出现错误
- ruby-on-rails - 在使用 minimagick 创建的 Ruby 中编辑 PDF 的元数据
- wordpress - 搜索查询的分页格式不正确 WP
- php - 与支付网关联系时延迟 PHP 代码一段时间
- node.js - 无法在 Strapi 项目中添加项目
- javascript - 用于显示和隐藏 html div 的 javaScript 函数不起作用
- python - 我需要显示所有可能的原始价格和最终价格
- c# - 使用构造函数在 swagger 中设置属性
- ember.js - 无法访问 Ember 中的会话数据(JWT 令牌数据)
- html - HTML锚电话标签格式