0

I want to rsync data to a remote computer, but I have to go through a tunnel. The following works already:

rsync -rvl -e "ssh -i $HOME/.ssh/id_rsa -J user@login.company.com" /home/data/  user@computer42:/home/data/

However, I have to enter two passwords each time.

Above I tried to pass an identity file, as suggested in How do you use an identity file with rsync?. However, I still get a request for the first password (while there is no error message).

Also I would like to how to pass the second identity file to overcome the second password request?

2 Answers2

1

First of all be sure you have your public key on both servers and that is working. and by working I mean if you ssh to both of them without a password

Then I would open an ssh tunnel first then connect to the tunnel, its a bit easier to debug if needed

ssh -L 2224:computer42:22 user@login.company.com -N &
rsync -arpve "ssh -p 2224" /home/data/ user@computer42:/home/data/
Tch
  • 1,055
  • 5
  • 11
1

You are getting a password prompt for the first login user@login.company.com because you are not providing any identity file for this login. Assuming you have already setup password-less SSH to this host (login.company.com) OR it's identity file to be at /path/to/login_company.pem, you can follow the following steps.

I am using SSH-config file (usually at ~/.ssh/config) to simplify the rsync command.

host final_destination
    HostName computer42
    User user
    IdentityFile ~/.ssh/id_rsa
    ProxyCommand ssh -W %h:%p -vvvv jump_host

host jump_host        
    HostName login.company.com
    User user
    IdentityFile ~/path/to/login_company.pem

At this point, following command should work without any password prompts and should take you to the host computer42 as user user.

ssh final_destination

Once this works, your rsync command becomes as simple as this;

rsync -az -vvvv /path/to/local/file final_destination:/path/to/destination -e "ssh"

PS:

The command that you provide as part of -e is being used to connect to the destination host. Since we are using SSH config-files, all we need to do now is to delegate the SSH connection setup to the ssh command. Everything required to reach the hosts is already configured in the config file. In contrast to the approach that you are taking, where you are configuring everything in line, the final command becomes

ssh -vvvv -i $HOME/.ssh/id_rsa -J user@login.company.com user@computer42

and if you run this command on your CLI, you'd get a password prompt which is the way rsync is behaving as well.

TIP: Moreover, you should run the SSH commands with -vvvv flag to print verbose output.

Maverick
  • 146
  • 8