skip to Main Content

i have an issue with my github action and i can’t connect with ssh i did this :

  • Create an ssh key with user adam

  • Copy the public key into /root/.ssh/authorized_keys

  • Create a secret in github with the public key

  • Create a script.sh into /home/adam/

  • chmod 600 .ssh directory

But i got this error :

Run ssh -o StrictHostKeyChecking=no
Warning: Identity file /home/adam/.ssh/id_rsa not accessible: No such file or directory.
Warning: Permanently added ‘my Ip’ (ED25519) to the list of known hosts.
adam@my Ip: Permission denied (publickey,password,keyboard-interactive).
Error: Process completed with exit code 255.

This is my code :

        name: Run script on VPS
on:
  push:
    branches: [master]
jobs:
  run-script:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Run script
        env:
          SSH_PRIVATE_KEY: ${{ secrets.VPS_SSH_PUBLIC_KEY }}
        run: |
          ssh -o StrictHostKeyChecking=no 
              -o PasswordAuthentication=no 
              -i /home/adam/.ssh/id_rsa 
              adam@myip 
              "bash /home/adam/script.sh"

Can someone help me fix this ?

  • tried to verify if the path to the id_rsa and id_rsa.pub is correct
  • saw both files were there and with the good key inside
  • tried reacreate ssh key multiples time
  • tried different way to access ssh
  • verify conf open ssh accept rsa and add this line CASignatureAlgorithms +ssh-rsa
  • restart service ssh

2

Answers


  1. Chosen as BEST ANSWER

    thank you for your answers I don't know exactly what was the issue but i think it was related with the ssh key

    I fixed my code by using password that is store in secret of github instead of ssh key

      name: Deploy 🚀
        on:
          push:
            branches:
              - master
        jobs:
          deploy:
            runs-on: ubuntu-latest
            steps:
              - name: Checkout code
                uses: actions/checkout@v2
              - name: Install Node.js
                uses: actions/setup-node@v2
                with:
                  node-version: '16.x'
              - name: Install dependencies
                run: npm install
              - name: Build project
                run: npm run build
              - name: SSH Deploy
                run: |
                  sshpass -p ${{ secrets.PSWD }} ssh -o StrictHostKeyChecking=no -p 22 ${{ secrets.USER}}@${{ secrets.VPS_IP }} 'cd /home/adam && ./deploy.sh'
                env:
                  SSHPASS: ${{ secrets.PSWD }}
    

  2. Copy the public key into /root/.ssh/authorized_keys

    That is on the remote target server you want to SSH to.

    And it means you want to SSH to as root: root@remoteServer:....
    Not as adam@...


    Instead of relying on local path which does not exist on GitHub runner (unless maybe self-hosted), you might want to use the GitHub Action "appleboy/ssh-action"

      - name: ssh key passphrase
        uses: appleboy/[email protected]
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USERNAME }}
          key: ${{ secrets.KEY }}
          port: ${{ secrets.PORT }}
          passphrase: ${{ secrets.PASSPHRASE }}
          script: |
            whoami
            ls -al
    

    Remove the passphrase: ${{ secrets.PASSPHRASE }} line if your SSH private key is not passphrase protected.

    That way, you do not need to create .ssh/ folder with the right permission. That action takes care of all that for you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search