SSH with Actions

Hi there,

Im trying to SSH via basic commands to my SSH server.

  • I added the correct pub key into my Server
  • I added 3 secrets in my Gitea Installation SSH_USER SSH_KEY SSH_HOST

where SSH_KEY is the actual private key

And Im using the following action.yaml

name: Gitea Actions Demo
run-name: ${{ }} is testing out Gitea Actions
on: [push]
    runs-on: ubuntu-latest
      - name: Check out repository code
        uses: actions/checkout@v3

      - name: Configure SSH
        run: |
          mkdir -p ~/.ssh/
          echo "$SSH_KEY" > ~/.ssh/staging.key
          chmod 600 ~/.ssh/staging.key
          cat >>~/.ssh/config <<END
          Host staging
            HostName $SSH_HOST
            User $SSH_USER
            IdentityFile ~/.ssh/staging.key
            StrictHostKeyChecking no
          cat ~/.ssh/config
          SSH_USER: ${{ secrets.SSH_USER }}
          SSH_KEY: ${{ secrets.SSH_KEY }}
          SSH_HOST: ${{ secrets.SSH_HOST }}

      - name: Test SSH
        run: ssh staging 'ls'

The output is as follow

I have the feeling that the 3 asterisk are places literally instead of the actual value due the error Load key "/***/.ssh/staging.key": invalid format

Is that correct?

Found the issue myself via this topic gitlab-ci SSH key invalid format - Stack Overflow

It seems that putting a value in the secret section of Gitea wipes out the last new line of the private_key. So I had to fix that by doing:

echo "$SSH_KEY" | tr -d '\r' > ~/.ssh/staging.key