GitHub Actions - Upload file using SCP

by
Jeremy Canfield |
Updated: December 19 2024
| GitHub Actions articles
GitHub Actions can be used to do something whenever something happens in one of your GitHub repositories. If you are not familiar with GitHub Actions, check out my article Getting Started with GitHub Actions.
Let's say you have a repository named my-repo that contains 2 files, foo.jpg and bar.jpg, perhaps like this.
- https://github.com/JohnDoe/my-repo/blob/main/images/foo.jpg
- https://github.com/JohnDoe/my-repo/blob/main/images/bar.jpg
Check out my article Public key authentication with OpenSSH on Linux for details on how to configure the target server to allow SSH connections.
You can SCP files using:
- The plain ole run command (this article)
- appleboy SCP action
The plain ole run command can be used to SCP one or more files in one of your GitHub repositories to one or more target servers.
name: GitHub Action
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
push:
branches:
- main
jobs:
github-action-job:
runs-on: ubuntu-latest
steps:
- name: Checking out the repository code . . .
uses: actions/checkout@v4
- name: copy foo.jpg to /tmp
run: scp foo.jpg ec2-user@ec2-10-11-12-13.compute-1.amazonaws.com:/tmp
Did you find this article helpful?
If so, consider buying me a coffee over at