23

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?

3 Answers 3

39

Specify "myvps" as the hostname.

rsync /var/bar myvps:/home/foo ...
1
  • doing rsync from user home dir where ssh config is kept, worked for me, even it supports node hoping. Nov 2, 2018 at 6:29
10

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
3
  • I realized that in my case I could not use the shortcut, but actual full host name could be used
    – dashesy
    Jun 25, 2014 at 2:37
  • 2
    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
    Aug 2, 2021 at 7:49
  • Using --rsh "ssh -F ${HOME}/.ssh/config" worked for my use case. I was able to rsync directly to Host aliases from my ~/.ssh/config. Used ${HOME} because tilde expansion did not work in my case. ymmv. Jan 20 at 23:30
0

@darKoram. For cases where you invoke ssh with non-standard path and try use ssh in ProxyCommand that is problem because there no inheritance. You have two option there: direct provide same file in inner command, or dynamically hack it. You may look detailed description in my blog post about that: http://hubbitus.info/wiki/Blog:Ssh_forwarding_with_same_config_file_hack

Shortly in you situation should help configuration like:

Host 21ct-dev1-*
  User cloud-user
  HostName %h.example.com
  ProxyCommand ssh $( egrep -z -A1 '^-F$' /proc/$PPID/cmdline ) 10.x.y.z -W %h:%p
  IdentityFile /path_to_vm_key
1
  • This is a comment to another answer, unrelated to the current question.
    – Kusalananda
    Aug 2, 2021 at 7:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .