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.