Rsync with Github actions when using a a custom port

18th Mar 2022

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.

$

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 $ -H $ >> ~/.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.

rsync -avz -e "ssh -p $" ./dist/ [email protected]$:/path-to-destination

That’s it.

If you enjoyed this article, please support me by sharing this article Twitter or buying me a coffee 😉. If you spot a typo, I’d appreciate if you can correct it on GitHub. Thank you!

Hold on while i sign you up…

🤗
Woohoo! You’re in!
Now, hold on while I redirect you.