easingthemes / ssh-deploy

GitHub Action for deploying code via rsync over ssh. (with NodeJS)
MIT License
1.19k stars 146 forks source link

Permission denied (publickey). #143

Open LeonardoFurtado opened 1 year ago

LeonardoFurtado commented 1 year ago

I'm trying to use this action, but the job is completed and the files are not uploaded.

My steps.

I create a new EC2 instance, downloaded de PEM that I generated when created the instance.

I've alocated a Elastic IP to my instance, So i'm using it on REMOTE_HOST secret

Added the default ubuntu name on REMOTE_USER secret

Copied the content of my .pem key on SSH_PRIVATE_KEY secret

I dont created a REMOTE_TARGET.

After execute the job I've received the following warnings and the folder was not upload to my ec2 instance.

image

This is my workflow.yml

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
  push:
    branches: [ "main" ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - run: npm ci
    - run: npm run build --if-present
    - name: Deploy to Staging server
      uses: easingthemes/ssh-deploy@main
      env:
        SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
        ARGS: "-rlgoDzvc -i"
        SOURCE: "dist/"
        REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
        REMOTE_USER: ${{ secrets.REMOTE_USER }}
        TARGET: ${{ secrets.REMOTE_TARGET }}
        EXCLUDE: "/dist/, /node_modules/"
        SCRIPT_BEFORE: |
          whoami
          ls -al
        SCRIPT_AFTER: |
          whoami
          ls -al
          echo $RSYNC_STDOUT
JonathanBooker912 commented 1 year ago

@LeonardoFurtado I had the same error, and it appears that this is the actual issue:

Load key "/home/runner/.ssh/deploy_key": error in libcrypto

I would double check that your private key secret has a newline character at the end of the file, because for some reason libcrypto requires it to be a "valid format"

LeonardoFurtado commented 1 year ago

@LeonardoFurtado I had the same error, and it appears that this is the actual issue:

Load key "/home/runner/.ssh/deploy_key": error in libcrypto

I would double check that your private key secret has a newline character at the end of the file, because for some reason libcrypto requires it to be a "valid format"

There is no newline character at the end of my file :/

cosin2077 commented 1 year ago

run this in your server: cd ~/.ssh && cat id_rsa.pub >> authorized_keys

This is a frustrating issue, even if you are deploying locally, you still need to add the public key to authorized_keys, otherwise you won't be able to login using your private key (and of course, you might need to configure some settings in sshd_config as well).

mansandersson commented 1 year ago

I have similar issue and problem on my side seems to be that the key file created by ssh-deploy has Windows line endings. I am able to reproduce issue using cmd line and the file produced by this action. After having run it through dos2unix command to fix line endings it starts working.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

mansandersson commented 1 year ago

Adding comment to remove stale label, issue has suggested solution and is waiting for maintainer approval.

pkkulhari commented 1 year ago

Don't know why, but the private key secret requires a new line character at the end (Just hit the enter key). It solved my problem.

easingthemes commented 1 year ago

This PR https://github.com/easingthemes/ssh-deploy/pull/156 should solve the issue

codespearhead commented 1 year ago

Don't know why, but the private key secret requires a new line character at the end (Just hit the enter key). It solved my problem.

This is seems to be one of those unwritten rules of *nix: [1] [2]

codespearhead commented 1 year ago

Given that #156 was merged in v4.1.10, this issue is probably fixed.

@LeonardoFurtado can you corroborate it and close the issue?

joebnb commented 1 year ago

image

using latest script also output error, and i also create a ubuntu docker contianer and use ssh-deploy generated script to mock github runner(in my case is under docker) connect server,it's works.

github-actions[bot] commented 12 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

qumberrizvi commented 12 months ago

Added public key to authorized_keys and added a new line to private key. The issue still persists.

github-actions[bot] commented 11 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 9 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

markgeraldnjau commented 9 months ago

Hello guys i did follow the same steps but i still get this error on attachment Screenshot 2024-01-12 at 18 21 54

intelligence commented 9 months ago

What solved it for me was to generate a new key as per: https://github.com/easingthemes/ssh-deploy?tab=readme-ov-file#1-ssh_private_key-required

Initially I was using my standard key, which had a passphrase, which caused issues.

qumberrizvi commented 9 months ago

What solved it for me was to generate a new key as per: https://github.com/easingthemes/ssh-deploy?tab=readme-ov-file#1-ssh_private_key-required

Initially I was using my standard key, which had a passphrase, which caused issues.

Mine doesn't have any paraphrases, yet the issue persists.

easingthemes commented 9 months ago

Can you try SCRIPT_BEFORE param, eg SCRIPT_BEFORE: ls. This will force known_hosts update, adding your host via ssh-keyscan

Abihsake commented 7 months ago

Added public key to authorized_keys and added a new line to private key. The issue still persists.

Did you resolved the Issue,

supuwoerc commented 5 months ago

I solved the problem smoothly this way, so if anyone else has this problem, try using my method. @Abihsake @qumberrizvi @markgeraldnjau https://github.com/easingthemes/ssh-deploy/issues/175#issuecomment-2128873743

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.