What you need to do in order to setup a basic Github Actions
On the server (droplet) create a new ssh key
ssh-keygen -t rsa -b 4096 -C "github-actions"
copy the key into ~/.ssh/authorized_keys
cat ~/.ssh/id_rsa.pub >> .ssh/authorized_keys
Copy the private key into your clipboard we need this next
cat ~/.ssh/id_rsa
After setting up the server's ssh, we need to login to the repo on github and head to the settings page.
Settings > Secrets > Add Secret
SSH_KEY
: private key (id_rsa
)HOST
: ip or domain nameUSERNAME
: user who will own the repository; I usedeployer
PORT
: defaults to 22, but better to be explicit even if you don't change it
Settings > Deploy Key > Add Deploy Key
Add the server's public key to this. I use the name of the server user; deployer
All the secrets and setup are adjusted for ssh-action.
Example .yml
file for a simple action which can ssh into our server
- name: SSH Remote Commands
uses: appleboy/[email protected]
env:
REPO: ${{ github.repository }}
with:
script_stop: true
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
port: ${{ secrets.PORT }}
key: ${{ secrets.SSH_KEY }}
envs: REPO
script: |
pwd
git pull
echo "git pull $REPO"