How to Sync Files/Directories Using Rsync with Non-standard SSH Port

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Use our Linode referral link if you plan to buy VPS (it starts at only $10/month).
  4. Support us via PayPal donate - Make a Donation
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Senthil Kumar

A Linux Consultant, living in India. He loves very much to write about Linux, Open Source, Computers and Internet. Apart from that, He'd like to review Internet tools and web services.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

Receive Your Free Complimentary eBook NOW! -

Download Free Linux eBooks

Linux BASH Programming Cookbook
Getting Started with Ubuntu 16.04
A Newbie's Getting Started Guide to Linux
Introduction to Linux - A Hands on Guide

You may also like...

6 Responses

  1. KRay says:

    If you get this article then you HAVE to take it to the next level. And yes — there are various ‘better’ ways to change/specify the ssh port and the connection ABSOLUTELY should be key’d, but I digress…

    The next level is doing a differential HARD-linked backup set.
    ie: I’ve already backed up the remote directory to local backup “1”.


    Put it all together (well, as I do it) for the second and onward backup:

    # rsync -avx --human-readable --progress --stats --delete --ignore-errors --force --exclude-from=${EXCLUDE_FILE} \
    --link-dest=/my_backups/1 -e 'ssh -p ${MY_PORT} ' ${USER}@${REMOTE_HOST}:/remote_directory/   /my_backups/2

    What this does only transfer new (or changed) files via rsync, otherwise we already have the file in the previous backup set, HARD-link to the file.
    This takes up no more space (except using another inode pointing to the data) — and the data exists until the last linked file is deleted.

    I have servers rsync’ing multiple times per hour allowing for snapshots, if you will, going back many many months with minimal overhead for ALL those backups (hundreds) — only new data. Wipe the oldest as space requires…

  2. GottZ says:

    lol. Security reasons.. did you ever hear about certificates?
    at least explain your concerns.
    in my case I noticed a Rapid decrease in attempts to login to my Servers by just removing root from password as well as key auth.
    unless someone knows your account name nobody could Start bruteforcing your password. though its better to just rely to passphrased ssh Keys only.

  3. BasketCase says:

    Just define your non-standard ssh ports in ~/.ssh/config file like so:

    Port 1431

    Now all ssh based tools will just work without any extra command line hassle.

  4. bjrosen says:

    The right way to do this is to put the port in the .ssh/config file, that way you don’t need to remember the port numbers. In addition to security the other advantage is that it allows you access many machines from a single IP address. On your router you need to port forward each port to the appropriate machine then you need to alias the different names to the same IP (this is easy to do if you are using as your dynamic DNS service, I’m sure it’s trivial with any DNS service). Once you’ve done that you can ssh into different machines by specifying the port number. Below is an example .ssh/config.

    Port 21010
    BatchMode yes
    Compression no
    KeepAlive yes

    Port 21011
    BatchMode yes
    Compression no
    KeepAlive yes

  5. Tomas says:

    You can also use rsyn -e “ssh -i private.key” together with custom SSH port for paswordless logins, quite handy.

    • BasketCase says:

      And you should put your non-standard ssh key files in ~/.ssh/config too using the IdentityFile setting. Note that whenever you specify an IdentityFile you should also turn on IdentitiesOnly.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

Join Over 300K+ Linux Users
  1. 177,942
  2. 8,310
  3. 37,548

Are you subscribed?