SysTutorials

Using Rsync with Non-Standard SSH Ports

· updated April 12, 2026

When you need to rsync against hosts behind NAT gateways or port-forwarded SSH services, the standard port 22 won’t work. The solution is the -e flag, which lets you specify a custom SSH command with your desired port.

Basic usage

Use -e to pass custom SSH arguments:

rsync -avxP --delete -e "ssh -p 13022" username@example.com:/remote/path/ /local/path/

Breaking this down:

Pushing vs pulling

The example above pulls (downloads) from a remote host. To push (upload) instead:

rsync -avxP --delete -e "ssh -p 13022" /local/path/ username@example.com:/remote/path/

Additional SSH options

You can pass multiple SSH arguments through the -e flag. Common scenarios:

Using a specific SSH key:

rsync -avxP -e "ssh -p 13022 -i ~/.ssh/custom_key" username@example.com:/remote/path/ /local/path/

Disabling host key verification (useful for ephemeral test environments, though not recommended for production):

rsync -avxP -e "ssh -p 13022 -o StrictHostKeyChecking=no" username@example.com:/remote/path/ /local/path/

Increasing SSH verbosity for debugging:

rsync -avvP -e "ssh -p 13022 -vv" username@example.com:/remote/path/ /local/path/

SSH config alternative

If you frequently connect to the same host, define it in ~/.ssh/config:

Host mycluster
    HostName example.com
    Port 13022
    User username
    IdentityFile ~/.ssh/custom_key

Then simplify your rsync command:

rsync -avxP --delete mycluster:/remote/path/ /local/path/

Performance considerations

For large transfers over high-latency networks, consider adding compression and tuning parameters:

rsync -avxP --delete -e "ssh -p 13022 -C" --bwlimit=5000 username@example.com:/remote/path/ /local/path/

For very large files, you might also want --partial-dir to handle incomplete transfers more gracefully:

rsync -avxP --delete --partial-dir=.rsync-partial -e "ssh -p 13022" username@example.com:/remote/path/ /local/path/

Troubleshooting

If the connection fails, verify SSH works directly first:

ssh -p 13022 username@example.com "ls /remote/path/"

Common issues:

Summary

The -e flag is the standard way to customize rsync’s SSH transport. For cluster environments with non-standard ports, define your hosts in SSH config once, then use clean, repeatable rsync commands without embedding port numbers in every command.

2026 Best Practices and Advanced Techniques

For Using Rsync with Non-Standard SSH Ports, understanding both the fundamentals and modern practices ensures you can work efficiently and avoid common pitfalls. This guide extends the core article with practical advice for 2026 workflows.

Troubleshooting and Debugging

When issues arise, a systematic approach saves time. Start by checking logs for error messages or warnings. Test individual components in isolation before integrating them. Use verbose modes and debug flags to gather more information when standard output is not enough to diagnose the problem.

Performance Optimization

Security Considerations

Security should be built into workflows from the start. Use strong authentication methods, encrypt sensitive data in transit, and follow the principle of least privilege for access controls. Regular security audits and penetration testing help maintain system integrity.

These complementary tools expand your capabilities:

Integration with Modern Workflows

Consider automation and containerization for consistency across environments. Infrastructure as code tools enable reproducible deployments. CI/CD pipelines automate testing and deployment, reducing human error and speeding up delivery cycles.

Quick Reference

This extended guide covers the topic beyond the original article scope. For specialized needs, refer to official documentation or community resources. Practice in test environments before production deployment.

← All posts