Maik Lowrey
Maik Lowrey

Reputation: 17556

GitHub Action: Accessing a Server from GitHub via SSH

I have a shell script that can connect to my server. It executes some shell commands there. Now I want to integrate the script into my GitHub action workflow. I have put the script in my repository and the script is also started. But I don't have any ssh commands yet, only echo commands in the script. Therefore it runs successfully.

Now I want to add the SSH commands to the script. But I wonder how I should handle the SSH key now. As I understand it, GitHub does not have a private key from which I can generate my public key and then store it on the server.

Upvotes: 1

Views: 4372

Answers (1)

VonC
VonC

Reputation: 1323753

You might consider using the GitHub Action appleboy/ssh-action

Executing remote ssh commands.

name: remote ssh command
on: [push]
jobs:

  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
    - name: executing remote ssh commands using password
      uses: appleboy/ssh-action@master
      with:
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USERNAME }}
        password: ${{ secrets.PASSWORD }}
        port: ${{ secrets.PORT }}
        script: whoami

You can register your private key and other sensitive data as GitHub secret for your repository.

Upvotes: 2

Related Questions