Rsync with a non-standard ssh port

While doing some work on the JQuery Plugins site today, I needed to use rsync over ssh. The ssh daemon on the remote server runs on a non-standard port, and all the port related options to rsync only change settings if you’re running the rsync-daemon.

After some searching, the man page of rsync finally offered a solution:


# rsync -avz -e "ssh -p $portNumber" [email protected]:/path/to/files/ /local/path/

Passing the port parameter to ssh with the -e option worked like a charm. 🙂

This is why Unix rocks.

Please note: I reserve the right to delete comments that are offensive or off-topic.

  • ikke

    Thanks for this….. Had the same problem, now the same solution 🙂

  • Daniel

    Wonderful… just what I was looking for…

  • Anonymous

    Thank you. This is why google rocks… “rsync ssh non standard port”. You helped a lot. Thanks for posting.

  • Colin-uk.com » Blog Archive » Rsync tips
  • ling

    Thanks a lot for this, just what I needed 😉

  • Leonardo Gregory Brunnet

    Thank you for the tip. It is always hard to grep solutions on man pages.

  • Tendydon

    Thanks a lot I was also wondering how

  • Leon Nardella

    Thank you very much!
    I had been losing my hair after this one!

  • Cristobal

     Gracias.

  • Guillermo

    That was indeed useful.

  • Jpenguin

    Cool useful!

  • Thanks a lot!

  • Marklar

    Anyone know how to get this to work on Windows?

    I installed cwRSync on Windows.  I tried the command, but when /local/path is C:something it gives an error about both directories being remote.  Any ideas?

    • synack

      Here is the comman fro the script that I use to backup my windows workstation to and offite linux box –  rsync -avzO -e “ssh -p 6883” –delete /cygdrive/c/data c %bkupuser%@bs01.g33k2.com:~/backups/daily01

      You have to used the /cygdrive/ when refering to local drives with cygwin tools.

  • Thanks man, this was exactly I was looking for! 🙂

  • Pete

    Ditto!!!

  • Joe

    Thanks!

  • Guug

    Well done! 🙂

  • Geno

    thanks a ton!

  • Expresso Viva

    god job
    thx lots

  • jon

    thank you…you saved me a whole lot of time

  • Adam

    Just to verify, will this login to an ssh shell before staring any rsync traffic?  I want to make sure the rsync is encrypted both directions before doing this to a remote server, i.e. it’s encrypted when I switch SRC/DEST:
    rsync -avz -e “ssh -p $portNumber” /local/path/ [email protected]:/path/to/files/

  • dave

    The post that keeps on giving. Thanks!

  • John Goodwin

     And another vote of thanks! Trying to backup all my data from my PC to my new HP N40L microserver and I fell at the first hurdle. A quick Google search and I found this. I pass on my thanks, cheers.

    John G

  • Alexey Moseyev

    Thank you!

  • Pingback: Rsync : Synchronize local with shared hosting « Welcome to Abdul Malik Ikhsan's Blog()

  • escapefromthebluebedroom

    Excellent, exactly what I was looking for!

  • Lee Burchett

    Thanks. This is just what I was looking for.

  • NO

    Thanks / Saved my “night” …

  • AsherBond

    I had a feeling I should have specified the port first. Helpful. – Asher Bond

  • thirdnormal

    Thank you. This worked perfectly for me.

  • Raul Montagne

    Thank you! just what I was looking for!

  • Cristóbal Vio

    thx!!

  • Pingback: Rsync with a non-standard ssh port – Mike Hostetler | Pork Belly()

  • VINOJ

    Thanks mate…

  • Perfect, just what I needed! Thanks.

  • Veerasamy Kaunder

    Thanks, i was needing this, and your suggestions worked.. Thanks again.

  • MrCambron

    I got some weird error message:
    ——-
    protocol version mismatch — is your shell clean?

    (see the rsync man page for an explanation)

    rsync error: protocol incompatibility (code 2) at /SourceCache/rsync/rsync-42/rsync/compat.c(61) [receiver=2.6.9]

    ——-

    My server is a Windows 7 machine and using some gui ssh server that I downloaded from a quick google search. And running the rsync command from my Mac OSX 10.9 machine.

  • David

    Thanks!

  • zaiger

    Perfect, I was missing the -e parameter. Thank you!

  • mjp1800

    This worked great for backing up a remote NAS to a local destination. How would the command be restructured for sending files in the other direction?

  • Pingback: 如何rsync同步非标准SSH接口 | argcv()

  • Thanks!

  • Awesome thanks

  • Bruno Sousa

    Thanks for this….. Had the same problem, now the same solution 🙂

  • Yay! Worked for me. Thanks!

  • tophibiz

    Works like e charm 10x

  • Thank you! This is the simplest solution. I’m surprised this isn’t mentioned enough anywhere else.

  • Wildan Fathan

    It’s work. thankyou bro

  • Robert Smith

    Thanks a lot!!

  • Zemtvs

    Thanks. I used $ sign with port number, then i realized that $ sign should not be used. worked

  • Katy

    Thanks!

  • Pingback: Rsync avec un port non standard - Hackeur.xyz()

  • Pingback: Rsync přes nestandardní port | Jr's page()

  • Ramires Teixeira

    Thank you so much for this!

  • Thomas Varghese

    Worked like a Charm!! 🙂

  • Grego

    Yep, worked for me. I saw –port=[otherport] on the manpage, but that didn’t work. Your parameter did the trick. Thanks

  • Al

    MASSIVE HELP! Thanks.

  • Stefan Petrounov

    Thanks for reminding us to read the manuals 🙂 And for the shortcut to the solution of course! Regards,
    Stefan

  • P.K. Hunter

    How about multifactor authentication. If SSH requires that verification code, how do we ensure rsync can also use that?

  • Hell Mouth

    Thumbs up!

  • good!

  • Luis Fontana

    Merci 🙂

  • Maja Kessler

    Big thanks! Still working fine in 2017 🙂