ssh-deploy icon indicating copy to clipboard operation
ssh-deploy copied to clipboard

Permission denied (publickey).

Open LeonardoFurtado opened this issue 1 year ago • 22 comments

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

LeonardoFurtado avatar Apr 23 '23 22:04 LeonardoFurtado

@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"

JonathanBooker912 avatar May 05 '23 23:05 JonathanBooker912

@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 :/

LeonardoFurtado avatar May 28 '23 14:05 LeonardoFurtado

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).

cosin2077 avatar Jun 27 '23 09:06 cosin2077

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.

mansandersson avatar Jul 26 '23 09:07 mansandersson

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] avatar Aug 26 '23 01:08 github-actions[bot]

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

mansandersson avatar Aug 26 '23 04:08 mansandersson

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.

pkkulhari avatar Sep 21 '23 17:09 pkkulhari

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

easingthemes avatar Sep 24 '23 15:09 easingthemes

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 avatar Sep 24 '23 15:09 codespearhead

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

@LeonardoFurtado can you corroborate it and close the issue?

codespearhead avatar Sep 30 '23 22:09 codespearhead

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.

joebnb avatar Oct 01 '23 14:10 joebnb

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] avatar Nov 06 '23 01:11 github-actions[bot]

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

qumberrizvi avatar Nov 07 '23 09:11 qumberrizvi

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] avatar Dec 08 '23 01:12 github-actions[bot]

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] avatar Jan 12 '24 01:01 github-actions[bot]

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

markgeraldnjau avatar Jan 12 '24 15:01 markgeraldnjau

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.

intelligence avatar Jan 18 '24 16:01 intelligence

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.

qumberrizvi avatar Jan 18 '24 17:01 qumberrizvi

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

easingthemes avatar Jan 31 '24 01:01 easingthemes

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

Did you resolved the Issue,

Abihsake avatar Mar 17 '24 11:03 Abihsake

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

supuwoerc avatar May 24 '24 08:05 supuwoerc

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] avatar Aug 23 '24 01:08 github-actions[bot]