ZL
About Articles Contact
Published on Mar 18, 2022
Filed under:
#devops,
#github actions,
#shell

Rsync with Github actions when using a a custom port

If you want to rsync with a custom port in a GitHub action, you need to do three steps:

  1. Add the port to as a secret
  2. Add the port to known_hosts file
  3. Perform the rsync action

This article picks off from Rsync with GitHub actions so make sure you read that article first if you’ve never tried to do a rsync in GitHub actions (without a custom port) yet.

Adding the port as a secret

Follow the same steps written in Rsync with GitHub actions to add the port as a secret.

You should be able to use the port like this when you’re done.

Terminal window
${{ secrets.SSH_PORT }}

Adding the port as to the known_hosts file

We need to add the port to the known_hosts file. If the port doesn’t exist, the ssh connection will fail.

You can add the port to the known_hosts file with the following code:

name: Deploy with rsync
run: ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts

-p specifies the port. Make sure -p goes before -H or you’ll receive an error.

Adding the port to the rsync command

You can add the port to the rsync command with the -e flag as I mentioned in rsync with a custom port.

Once you add the -e flag, you can use -p to specify the custom port.

Terminal window
rsync -avz -e "ssh -p ${{ secrets.SSH_PORT }}" ./dist/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/path-to-destination

That’s it.

Previous Here’s how to quickly test components that use container queries Next The Magical Dev School Student Portal is live!

Join My Newsletter

I share what I’m learning on this newsletter: code, building businesses, and living well.

Sometimes I write about technical deep-dives, product updates, musings on how I live, and sometimes my struggles and how I’m breaking through.

Regardless of the type of content, I do my best to send you at least one insightful piece every week.

If you’re into making things and growing as a person, you’ll probably feel at home here.

“

Zell is the rare sort of developer who both knows his stuff and can explain even the most technical jargon in approachable — and even fun — ways!

I’ve taken his courses and always look forward to his writing because I know I’ll walk away with something that makes me a better front-ender.

Geoff Graham
Geoff Graham — Chief Editor @ CSS Tricks
The Footer

General

Home About Contact Testimonials Tools I Use

Projects

Magical Dev School Splendid Labz

Socials

Youtube Instagram Tiktok Github Bluesky X

Follow Along

Email RSS
© 2013 - 2026 Zell Liew / All rights reserved / Terms