ssh-key-action icon indicating copy to clipboard operation
ssh-key-action copied to clipboard

Rsync fails Permission denied (publickey)

Open shubhank008 opened this issue 2 years ago • 2 comments

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/[email protected]
  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/[email protected]
        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/    

shubhank008 avatar Jan 25 '23 13:01 shubhank008

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

splitbrain avatar Apr 07 '23 11:04 splitbrain

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?

RevealedFrom avatar Oct 20 '23 14:10 RevealedFrom