How to use `~/.ssh/config` setting for each server by `rsync`

22,359

Solution 1

Specify "myvps" as the hostname.

rsync /var/bar myvps:/home/foo ...

Solution 2

This did not work for me. I have jump hosting in my ~/.ssh/config

Host 10.x.y.z
    User cloud-user
    HostName vm-pivot
    IdentityFile /path_to_vm_key

Host 21ct-dev1-*
    User cloud-user
    HostName %h.example.com
    ProxyCommand ssh 10.x.y.z -W %h:%p
    IdentityFile /path_to_vm_key


rsync -e "ssh" local_path vm-app01:/remote_path

ssh: Could not resolve hostname vm-app01: nodename nor servname provided, or not known rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [sender=2.6.9]

However, this works just fine

[kbroughton@kbroughton:project + (develop)] ssh vm-app01
Last login: Thu Apr 17 12:10:37 2014 from 10.a.b.c

Edit, I was able to get past the name resolution by forcing rsync ssh to load a config file with -F sudo rsync -az -e "ssh -F /Users/kbroughton/.ssh/config"

This gets past one error but onto another. Permission denied (publickey,gssapi-keyex,gssapi-with-mic). ssh_exchange_identification: Connection closed by remote host

Also tried explicitly setting -i and user@ in the connection but same error occurs.

EDIT

Another data point. If i use the floating ip of the pivot vm (jump host) instead of its name vm-pivot rsync works. But explicitly dumping all my ssh/config in the -e "ssh" does not work. Details: local mac, upgraded to rsync 3.1.0, remote centos rsync 3.0.9.

[kbroughton@kbroughton:project + (develop)] sudo /usr/local/bin/rsync -az -e "ssh -F /Users/kbroughton/.ssh/config -i /Users/kbroughton/.ssh/identities/vm_key -W 10.x.y.z:22"  /var/data/sources/data.tar.gz user@vm-pivot:/home/user

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
ssh_exchange_identification: Connection closed by remote host
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.0]

[kbroughton@kbroughton:project + (develop)] sudo /usr/local/bin/rsync -az -e "ssh -F /Users/kbroughton/.ssh/config -i /Users/kbroughton/.ssh/identities/vm_key -W 10.x.y.z:22"  /var/data/sources/data.tar.gz [email protected]:/home/user
protocol version mismatch -- is your shell clean?
(see the rsync man page for an explanation)
rsync error: protocol incompatibility (code 2) at compat.c(181) [sender=3.1.0]

This works

[kbroughton@kbroughton:project + (develop)] sudo /usr/local/bin/rsync -az -e "ssh -F /Users/kbroughton/.ssh/config -i /Users/kbroughton/.ssh/identities/vm_key"  /var/data/sources/data.tar.gz [email protected]:/home/user
Share:
22,359

Related videos on Youtube

ironsand
Author by

ironsand

Updated on September 18, 2022

Comments

  • ironsand
    ironsand over 1 year

    I'm now using rsync with -e 'ssh -p 10022' option to specify the port.

    I have already ssh setting in ~/.ssh/config.

    Host myvps
      HostName example.com
      User ironsand
      Port 10022
    

    Can I use this config from rsync easily? Or Can I create ~/.rsync and set a default port for specify server?

  • dashesy
    dashesy almost 10 years
    I realized that in my case I could not use the shortcut, but actual full host name could be used
  • Stalin Gino
    Stalin Gino over 5 years
    doing rsync from user home dir where ssh config is kept, worked for me, even it supports node hoping.
  • Kusalananda
    Kusalananda over 2 years
    This answer seems to be more of a working through of issues that are not directly related to the current question. It may be better presented as a separate question and answer, if a explanation of the issue and the solution could be formulated. The main issue seems to be that you don't actually use a hostname listed in your SSH configuration.
  • Kusalananda
    Kusalananda over 2 years
    This is a comment to another answer, unrelated to the current question.