shimataro / ssh-key-action

GitHub Action that installs SSH key to .ssh
https://github.com/marketplace/actions/install-ssh-key
MIT License
581 stars 87 forks source link

Rsync fails Permission denied (publickey) #233

Open shubhank008 opened 1 year ago

shubhank008 commented 1 year ago

Install SSH Key working

Run shimataro/ssh-key-action@v[2](https://github.com/gamerplex/kinland2/actions/runs/4005511431/jobs/6876611514#step:3:2)
  with:
    key: ***

    name: id_rsa
    known_hosts: just-a-placeholder-so-we-dont-get-errors
    if_key_exists: replace
SSH key has been stored to /home/runner/.ssh successfully.

But when running rsync command, it fails

Run rsync -avzr ./build/WebGL/* root@***:/home/steve777/apps/***-Web/                 
  rsync -avzr ./build/WebGL/* root@***:/home/steve777/apps/***-Web/                 
  shell: /usr/bin/bash -e {0}
root@***: Permission denied (publickey).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code [2]
Error: Process completed with exit code 2[5]

I am also using appleboy/ssh-action with same host and private_key but that works fine.

Run appleboy/ssh-action@v0.1.6
  with:
    host: ***
    username: root
    key: ***
    port: 22
    script: cd /home/steve777/apps/***-Web
  rm -rf *

    sync: false
    use_insecure_cipher: false
    timeout: 0s
    command_timeout: 10m
    proxy_port: 22
    proxy_timeout: 30s
    proxy_use_insecure_cipher: false
    script_stop: false
    debug: false

======CMD======
cd /home/steve[7](https://github.com/gamerplex/kinland2/actions/runs/4005511431/jobs/6876611514#step:7:7)77/apps/Kinland-Web
rm -rf *

======END======
==============================================
✅ Successfully executed commands to all host.
==============================================

Workflow

deployToWebServer:
    needs: [BuildWebGL]
    #runs-on: self-hosted
    runs-on: ubuntu-latest
    steps:
      - name: Install SSH Key
        uses: shimataro/ssh-key-action@v2
        with:
          key: ${{ secrets.SSH_PRIVATE_KEY }} 
          name: id_rsa
          known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
          if_key_exists: replace

      - name: Adding Known Hosts
        run: ssh-keyscan -H ${{ secrets.SSH_HOST_WEBGL }} >> ~/.ssh/known_hosts

        #Checkout
      - uses: actions/checkout@v3
        with:
            #fetch-depth: 0
            #Branch
            ref: main
            fetch-depth: 1
            submodules: recursive
            #token:  ${{ secrets.MY_PAT }}

        #Repeat for all builds, copy paste this step
      - name: Download WebGL Artifact
        uses: actions/download-artifact@v2
        with:
          name: Build-WebGL
          path: build/WebGL

      - name: Cleanup Remote Old Files
        uses: appleboy/ssh-action@v0.1.6
        with:
            host: ${{ secrets.SSH_HOST_WEBGL }}
            username: root
            key: ${{ secrets.SSH_PRIVATE_KEY_WEBGL }} 
            port: 22
            script: |
              cd /home/steve777/apps/***-Web
              rm -rf *

      - name: Deploy with rsync
        run: |
            rsync -avzr ./build/WebGL/* root@${{ secrets.SSH_HOST_WEBGL }}:/home/steve777/apps/***-Web/    
splitbrain commented 1 year ago

I had the same problem. Adding the user's public key to the authorized_keys file fixed the issue for me.

RevealedFrom commented 1 year ago

I had the same problem. Adding the user's public key to the authorized_keys file fixed the issue for me.

I am getting a similar Permission denied issue. Which "user" are you referring to, and the authorized_keys file on where?