Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied (publickey). #143

Open
LeonardoFurtado opened this issue Apr 23, 2023 · 23 comments
Open

Permission denied (publickey). #143

LeonardoFurtado opened this issue Apr 23, 2023 · 23 comments

Comments

@LeonardoFurtado
Copy link

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
Copy link

@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
Copy link
Author

@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
Copy link

cosin2077 commented Jun 27, 2023

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
Copy link
Contributor

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
Copy link

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 github-actions bot added the stale Issues without activity label Aug 26, 2023
@mansandersson
Copy link
Contributor

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

@github-actions github-actions bot removed the stale Issues without activity label Aug 27, 2023
@pkkulhari
Copy link

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
Copy link
Owner

This PR #156 should solve the issue

@codespearhead
Copy link
Collaborator

codespearhead commented Sep 24, 2023

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
Copy link
Collaborator

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

@LeonardoFurtado can you corroborate it and close the issue?

@joebnb
Copy link

joebnb commented Oct 1, 2023

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.

Copy link

github-actions bot commented Nov 6, 2023

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 github-actions bot added the stale Issues without activity label Nov 6, 2023
@qumberrizvi
Copy link

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

@github-actions github-actions bot removed the stale Issues without activity label Nov 8, 2023
Copy link

github-actions bot commented Dec 8, 2023

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 github-actions bot added the stale Issues without activity label Dec 8, 2023
@easingthemes easingthemes removed the stale Issues without activity label Dec 12, 2023
Copy link

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 github-actions bot added the stale Issues without activity label Jan 12, 2024
@markgeraldnjau
Copy link

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

@github-actions github-actions bot removed the stale Issues without activity label Jan 13, 2024
@intelligence
Copy link

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
Copy link

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
Copy link
Owner

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

@Abihsake
Copy link

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

Did you resolved the Issue,

@supuwoerc
Copy link

I solved the problem smoothly this way, so if anyone else has this problem, try using my method.
@Abihsake @qumberrizvi @markgeraldnjau
#175 (comment)

Copy link

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 github-actions bot added the stale Issues without activity label Aug 23, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2024
@easingthemes easingthemes reopened this Sep 7, 2024
@github-actions github-actions bot removed the stale Issues without activity label Sep 8, 2024
@DavidingPlus
Copy link

From my situation, consider these details. It helped me and I really hope that helps you a lot.

Pay attention to SSH_PRIVATE_KEY configuration. It's written clearly in README. As it can tell, the public key part should be added to the authorized_keys file on the server. The public key part is in the file is_rsa.pub.

image

Further more, notice env in the workflow file, especially SSH_PRIVATE_KEY. You need to find it the file id_rsa. Copy all contents of the file. Your file is like as below:

-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----

Pay Attention once again that copy all contents of this file including comments like -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY-----. Otherwise it might fail. At least for me it works well.

Hope it can help you guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests