I'm trying to rsync from my MacOS machine to an Ubuntu server that's running on Windows Azure. To ssh to it, I have to do the following:

 $ ssh -i  myPrivateKey.key -p 22 me@me.cloudapp.net

I think the key file might be an X509 public key, if that helps (sorry, I'm no sysadmin). Anyway, I can ssh successfully with the above command.

Now I'd like to rsync files to the remote server. Do I need to supply the .key file as an option somehow?

A normal rsync command fails:

$ sudo rsync -avz -e my/file me@me.cloudapp.net:/my/path
    rsync: Failed to exec my/file: Permission denied (13)
rsync error: error in IPC code (code 14) at /SourceCache/rsync/rsync-42/rsync/pipe.c(86) [receiver=2.6.9]
    rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
    rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [receiver=2.6.9]

The command fails not because of wrong keys, but because you're telling rsync to run my/file instead of ssh (by using the -e option, which picks up the word following it). Remove the -e option first.

Since rsync normally uses ssh to connect, you can configure both to always use a particular key for connecting to cloudapp. For example, put this at the top of your ~/.ssh/config file:

Host me.cloudapp.net
    Username me
    IdentityFile ~/my-cloudapp-key.key
    IdentitiesOnly yes

The Username me part will also let you skip adding me@ when using ssh or rsync. Plain rsync -avz my/file me.cloudapp.net:/my/path will work.

Note: SSH keys are not X.509 certificates; they're just plain RSA or ECDSA keypairs without any additional information.

  • 3
    On Ubuntu it seems to be User instead of Username – Thomas Weller Jan 9 '16 at 23:21
  • If you need a different port than 22 you can add a line with Port 8023. Alternatively you will have to add --rsh='ssh -p8023' directly to the command line. – TheStoryCoder Mar 29 '17 at 12:47
  • 1
    On macOS too, it's User instead of Username, else I get Bad configuration option: username. – miguelmorin Apr 4 '20 at 17:22
  • Most time saving tip ever! Esp. with the comments about Ubuntu and macOS. Thx all. – Ian Lovejoy Feb 8 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.