garygrossgarten / github-action-scp

⬆️ Copy a folder to a remote server using SSH
MIT License
192 stars 53 forks source link

Using RSA Private Key to Deploy in EC2 #30

Open lhcavalcanti opened 3 years ago

lhcavalcanti commented 3 years ago

Hello,

I'm trying to deploy the build of my app through the SCP directly in my EC2 instance, but I'm getting error in reading the key file (it is private RSA key from AWS).

Error:

⚠️ The GitHub Action couldn't connect to *** Error: Cannot parse privateKey: Unsupported key format
    at Client.module.exports.597.Client.connect (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11745:13)
Error: Cannot parse privateKey: Unsupported key format
    at /home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:10148:24
    at new Promise (<anonymous>)
    at NodeSSH.connect (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:10128:15)
    at /home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11364:23
    at Generator.next (<anonymous>)
    at /home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11282:71
    at new Promise (<anonymous>)
    at module.exports.526.__awaiter (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11278:12)
    at connect (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11347:12)
Starting scp Action: m3s-app.zip to /home/ubuntu/
⚠️ An error happened:(. Not connected Error: Not connected
Error: Not connected

Workflow config:

Am I doing something wrong? Or it does not support this type of key?

Thanks!

MaLIE2018 commented 2 years ago

I have the same problem, that it is not clear to me, why my key is not accepted. EDIT: key was incorrectly copied from wsl2 terminal to github. 🤪

Dud3core-webdev commented 2 years ago

I have the same problem trying to connect to a Digital Ocean Droplet.

The key format is

-----BEGIN OPENSSH PRIVATE KEY-----
{{key data}}
-----END OPENSSH PRIVATE KEY-----

my deploy script looks like this

name: .NET

on:
  push:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x
    - name: Restore dependencies
      run: dotnet restore
    - name: Release Build
      run: dotnet build --configuration Release --no-restore
    - name: Test
      run: dotnet test --verbosity normal
    - name: Start Deploy
      uses: garygrossgarten/github-action-scp@release
      with: 
        local: /home/runner/work/MfWebDevApiCore/MfWebDevApiCore/MfWebDevServiceNew/bin/Release
        remote: var/www/MfWebDevServices
        host: ${{ secrets.SSH_HOST }}
        username: ${{ secrets.SSH_USERNAME }}
        privateKey: ${{ secrets.SSH_KEY }}
        rmRemote: true
        dotfiles: true

Full output from run:

Run garygrossgarten/github-action-scp@release
⚠️ The GitHub Action couldn't connect to ***. Error: Cannot parse privateKey: Failed to generate information to decrypt key
Establishing a SSH connection to ***.
    at Client.module.exports.597.Client.connect (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11745:13)
    at /home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:10148:24
    at new Promise (<anonymous>)
    at NodeSSH.connect (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:10128:15)
    at /home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11364:23
    at Generator.next (<anonymous>)
    at /home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11282:71
    at new Promise (<anonymous>)
    at module.exports.526.__awaiter (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11278:12)
    at connect (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11347:12)
⚠️ An error happened:(. Not connected Error: Not connected
    at Client.module.exports.597.Client.exec (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:12224:11)
    at /home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:10228:24
    at new Promise (<anonymous>)
    at NodeSSH.execCommand (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:10227:16)
    at /home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11434:23
    at Generator.next (<anonymous>)
    at /home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11282:71
    at new Promise (<anonymous>)
    at module.exports.526.__awaiter (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11278:12)
    at cleanDirectory (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:11432:12)
using provided private key
⚠️ An error happened:(. Not connected to server Error: Not connected to server
    at NodeSSH.getConnection (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:10073:19)
    at NodeSSH.requestSFTP (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:10189:33)
    at NodeSSH.putDirectory (/home/runner/work/_actions/garygrossgarten/github-action-scp/release/dist/index.js:10420:47)
Error: Cannot parse privateKey: Failed to generate information to decrypt key
Starting scp Action: /home/runner/work/MfWebDevApiCore/MfWebDevApiCore/MfWebDevServiceNew/bin/Release to var/www/MfWebDevServices
Error: Not connected
 1: 0x9da7c0 node::Abort() [/home/runner/runners/2.285.1/externals/node12/bin/node]
 2: 0xa4e219  [/home/runner/runners/2.285.1/externals/node12/bin/node]
 3: 0xba5d59  [/home/runner/runners/2.285.1/externals/node12/bin/node]
 4: 0xba7b47 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/home/runner/runners/2.285.1/externals/node12/bin/node]
 5: 0x13750d9  [/home/runner/runners/2.285.1/externals/node12/bin/node]

EDIT: SOLVED, SSH key was encrypted with a passphrase

matheusfrancisco commented 2 years ago

@Dud3core-webdev I have had this same problem, how did u solve this?

Dud3core-webdev commented 2 years ago

@matheusfrancisco I added my SSH passphrase with the call:

- name: Deploy to Digital Ocean
        uses: appleboy/scp-action@master
        with:
          source: path/bin/Release
          target: var/www/path
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          passphrase: ${{ secrets.SSH_PASSWORD }} <-- This was missing
          rm: true

It worked every time after that