← Back to blog
How to Run SSH Commands on Your Server with GitHub Actions
- Published on
- • 1 mins read•--- views
On host machine
ssh-keygen -t rsa -b 4096 -C "<YOUR_EMAIL>"
In workflow.yml
deploy:
needs: publish
name: Deploy to VPS
runs-on: ubuntu-latest
steps:
- name: Install ssh keys
run: |
mkdir -p ~/.ssh
echo "${{secrets.APP_SSH_PRIVATE_KEY}}" > ~/.ssh/id_rsa_${{env.SERVICE_NAME}}
chmod 600 ~/.ssh/id_rsa_${{env.SERVICE_NAME}}
cat >>~/.ssh/config <<EOF
Host ${{env.SERVICE_NAME}}
HostName ${{env.APP_SSH_HOST}}
Port ${{env.APP_SSH_PORT}}
User ${{env.APP_SSH_USER}}
IdentityFile ~/.ssh/id_rsa_${{env.SERVICE_NAME}}
StrictHostKeyChecking no
EOF
- name: Connect and pull
run: |
ssh ${{env.SERVICE_NAME}} -p ${{env.APP_SSH_PORT}}
cd ${{env.APP_SSH_WORKDIR}}
echo ${{secrets.PAT}} | docker login ghcr.io -u ${{github.actor}} --password-stdin
docker compose pull ${{env.SERVICE_NAME}}
docker compose up -d ${{env.SERVICE_NAME}}
exit
- name: Cleanup
run: rm -rf ~/.ssh
Table of Contents
Related
Posts
Fast GAC Deployment and App Pool Recycle for SharePoint Development
A practical guide for SharePoint developers to quickly deploy DLLs to the GAC and recycle IIS app pools using Visual Studio, PowerShell scripts, and VsCommandBuddy.
Make delivery a consequence of payment, not a task someone performs
Digital goods delivered by hand are limited by working hours and protected only by attention. Moving delivery onto order events changes what the system guarantees, and the API is what stops a second channel becoming a second implementation.
Programming and Scripting for Cybersecurity: Part 4, Cross-Platform Monitoring Workflows
Part 4 delivers a cross-platform monitoring exercise with Python and PowerShell, focusing on log analysis, reporting, and operational safeguards.
Open for contract collaboration
I am available for contract-based collaboration. If you have an interesting project idea, schedule a call via Calendly.
Schedule a 30-min call