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 Rendering MDX in a Svelte component when using Astro Next The Spirit of CSS Tricks is now gone

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 to live, and sometimes my struggles and how I’m breaking through.

Regardless of the type of content, I do my best to send you an update every week.

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

“

Zell is one of those rare people who commands tremendous knowledge and experience but remains humble and helpful. They want you to know what they know, not just be impressed by it.

In other words, Zell is a natural teacher. You’re lucky to have him because he feels lucky to be able to help you in your journey.

Heydon Pickering
Heydon Pickering — Web & Accessibility Extraordinaire
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 - 2025 Zell Liew / All rights reserved / Terms