Rsync is a fast and extraordinarily versatile file-copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. When copying over ssh, rsync will need to authenticate with the receiving side using either password or key authentication. Since it’s a backup tool, and most of the time will be automated, we want to connect with the receiving side without prompting for password – using key authentication.
Step 1 – Generate RSA keys on the source server
ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is:
Step 2 – Copy the key to the destination server
ssh-copy-id -i root@target-server-domain-or-ip.com root@target-server-domain-or-ip.com's password: Now try logging into the machine, with "ssh 'root@target-server-domain-or-ip.com'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
If you are using an alternate ssh port (not 22), you can try and use this syntax –
ssh-copy-id "-p 1234" user@target-server-domain-or-ip.com
Replace “1234” with your port
Now test ssh connection from the source server to the destination server –
ssh root@target-server-domain-or-ip.com
When doing the first login you will be notified about “RSA key fingerprint” issue, approve it so he will be added “known_hosts” so the alert won’t show up again.
Tags: rsync, ssh
your command to copy the public key to the destination server is not correct – you are missing the pub cert after -i
`ssh-copy-id -i /root/.ssh/id_rsa.pub root@target-server-domain-or-ip.com`
If you use the command ssh-copy-id -i without specifying anything after the -i, the command will default to using the public key file located at ~/.ssh/id_rsa.pub on your local machine. This file typically contains your default RSA public key, which is the most commonly used key for SSH.
In other words, if you don’t specify a particular key with -i, ssh-copy-id will attempt to copy your default RSA public key to the ~/.ssh/authorized_keys file of the remote user’s account (in this case, root) on the target server. This is under the assumption that you have already generated an RSA key pair on your local machine and the public key is stored in the standard location.
If you haven’t generated an RSA key pair, or if the public key is not in the default location, the command will fail and likely display an error message indicating that it can’t find the key file.
well – for me it gave an error `/usr/bin/ssh-copy-id: ERROR: failed to open ID file ‘root@192.168.188.188.pub’: No such file` for the command `ssh-copy-id -i root@192.168.188.188`