Search code examples
node.jsgitsshgitlab-cigitlab-ci-runner

Auto deploy github with action throug ssh return rsync exited with code 255


I want to deploy my NodeJS GitHub project to my VPs using ssh, so I make this script in .github/workflows :

  
name: Node CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Install Node.js
      uses: actions/setup-node@v1
      with:
        node-version: '10.x'
    - name: Install npm dependencies
      run: npm install
    - name: Run build task
      run: npm run build --if-present
    - name: Deploy to Server
      uses: easingthemes/ssh-deploy@v2.2.11
      env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY }}
          ARGS: "-rltgoDzvO --delete"
          SOURCE: "/"
          REMOTE_HOST: ${{ secrets.HOST }}
          REMOTE_USER: ${{ secrets.USERNAME }}
          TARGET: ${{ secrets.FOLDER_TARGET }}
          EXCLUDE: "/dist/, /node_modules/"

I enter every information in my secret repository key. And to generate the ssh key, I'm using this command : ssh-keygen -m PEM -t rsa -b 4096 with not paraphrase. And I have passed the ~/.ssh/id_rsa` string inside SSH_KEY value

But after all of that, I have this error when run the action script:

Run easingthemes/ssh-deploy@v2.2.11
[general] GITHUB_WORKSPACE:  /home/runner/work/Litopia.fr/Litopia.fr
[SSH] Creating /home/runner/.ssh dir in  /home/runner/work/Litopia.fr/Litopia.fr
✅ [SSH] dir created.
[SSH] Creating /home/runner/.ssh/known_hosts file in  /home/runner/work/Litopia.fr/Litopia.fr
✅ [SSH] file created.
✅ Ssh key added to `.ssh` dir  /home/runner/.ssh/deploy_key
[Rsync] Starting Rsync Action: /home/runner/work/Litopia.fr/Litopia.fr// to ***@***:***
[Rsync] exluding folders /dist/,/node_modules/
⚠️ [Rsync] error:  rsync exited with code 255
⚠️ [Rsync] stderr:  Warning: Permanently added '***,82.65.27.189' (ECDSA) to the list of known hosts.
Permission denied, please try again.
Permission denied, please try again.
***@***: Permission denied (publickey,password).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]

⚠️ [Rsync] stdout:  
⚠️ [Rsync] cmd:  rsync /home/runner/work/Litopia.fr/Litopia.fr// ***@***:*** --rsh "ssh -p 22 -i /home/runner/.ssh/deploy_key -o StrictHostKeyChecking=no" --recursive --exclude=/dist/ --exclude=/node_modules/ -rltgoDzvO --delete
 1: 0x9da7c0 node::Abort() [/home/runner/runners/2.278.0/externals/node12/bin/node]
 2: 0xa4e219  [/home/runner/runners/2.278.0/externals/node12/bin/node]
 3: 0xba5d59  [/home/runner/runners/2.278.0/externals/node12/bin/node]
 4: 0xba7b47 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/home/runner/runners/2.278.0/externals/node12/bin/node]
 5: 0x13750d9  [/home/runner/runners/2.278.0/externals/node12/bin/node]

Solution

  • Check first that, as mentioned in easingthemes/ssh-deploy README, the public key part has been added to the authorized_keys file on the server that receives the deployment.

    Try and test it with

    ssh -Tv -i /home/runner/.ssh/deploy_key -o StrictHostKeyChecking=no $REMOTE_USER@$REMOTE_HOST
    

    The OP MrSolarius adds in the comments:

    I have use my private key instead of my public key, so now it works.