github动作:SSH进入液滴并运行代码

发布于 2025-02-06 05:31:54 字数 1289 浏览 3 评论 0原文

当我将代码推向GitHub时,我想通过GitHub操作自动部署GitHub项目。我的YAML文件看起来像这样:

name: push-and-deploy-to-server

on:
  push:
    branches: [ main ]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: appleboy/scp-action@master
        with:
          host: ${{ secrets.SSH_HOST }}
          port: 22
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          source: "."
          target: "."
      - uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.SSH_HOST }}
          port: 22
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          script: |
            npm install
            pm2 restart index.js

我有一台带有SSH KePair的服务器。将公共密钥添加到服务器授权_Keys,我可以通过终端到服务器的端子。

当我将代码推到GitHub回购时,操作会运行。我会收到以下错误:

无人机-SCP错误:SSH:握手失败:SSH:无法进行身份验证,尝试的方法[无公共键],没有支持的方法仍然存在

很奇怪,是:在此错误之后,我无法再进入我的服务器,即使通过我的控制台我得到了“允许拒绝(publicKey)”。因此,在运行github动作之前,一切都可以使用,之后会失败。

服务器的IP地址是SSH_HOST,我用来将SSH用于SSH的用户名是在SSH_USERNAME中设置的,而私钥(与我在本地笔记本电脑上使用的SSH在SSH中使用的相同)是在SSH_PRIVATE_KEY中设置的。

以前有人遇到过同样的问题吗?我真的不知道这里发生了什么。

编辑:额外信息:它是私有存储库。

I want to deploy a github project automatically through github actions when I push my code to github. My yaml-file looks like this:

name: push-and-deploy-to-server

on:
  push:
    branches: [ main ]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: appleboy/scp-action@master
        with:
          host: ${{ secrets.SSH_HOST }}
          port: 22
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          source: "."
          target: "."
      - uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.SSH_HOST }}
          port: 22
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          script: |
            npm install
            pm2 restart index.js

I have a server with an SSH keypair. The public key is added to the server authorized_keys, and I can SSH through my terminal to the server.

When I push code to the github repo, the action runs. I get the following error:

drone-scp error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

The weird thing is: after this error, I'm not able to SSH into my server anymore, even through my console I get a "Permission denied (publickey)". So before running the github action, everything works, after that it fails.

The ip address of the server is SSH_HOST, the username which I use to SSH into the server is set in SSH_USERNAME and the private key (the same as I use on my local laptop to ssh into the server) is set in SSH_PRIVATE_KEY.

Does anyone have encountered the same problem before? I have really no clue whats going on here.

Edit: extra information: it's a private repository.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

汐鸠 2025-02-13 05:31:54

这是一个超级的答案,但是我遇到了试图将某些东西部署到Droplot上的同样问题。我创建了一个SSH键,并且正在获取ssh握手失败也要做的事情是我要做的就是将公共密钥添加到我的授权密钥列表中:

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

This is a super late answer but i was running into the same problem with trying to deploy something onto a droplot. I created an ssh key and was getting the ssh handshake failed issue also the thing that I had to do was add the public key to my authorized key list:

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文