Rsync with Github actions when using a a custom port18th Mar 2022
If you want to rsync with a custom port in a GitHub action, you need to do three steps:
- Add the port to as a secret
- Add the port to known_hosts file
- 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