I want to use rsync command between two computers and both of them have RedHat 5.3 , when I googled for way to make that, I discovered that I have to make public key between them to not prompt password when I use rsync command. What is the best way to get a public key and make rsync work perfectly.
Note: I followed many tutorials and I did not find authorized_keys (under /root/.ssh/). I found known hosts file.
A public/private keypair needs to be created on the machine you want to connect from then the public key needs to be copied to the machine you want to connect to. For this explaination lets call the machine you want to connect from local and the machine you want to connect to remote.
Step 1 - Generate the keypair on local
This command will create id_dsa and id_dsa.pub in your home folder, i.e. ~/.ssh/id_dsa and ~/.ssh/id_dsa.pub
Step 2 - Add the public key to the authorized_keys file on the machine you want to connect to.
You should now be able to connect to the remote machine using the key.
When you want to use ssh with keys, the first thing that you will need is a key.
When asked for a "passphrase", we won't enter one. Just press enter twice. The ssh-keygen program will now generate both your public and your private key, by default, your keys are stored in the .ssh/ directory in your home directory.creating key using dsa encryption (or replace dsa by rsa for rsa encryption)
To be able to log in to remote systems using your pair of keys, you will first have to add your public key on the remote server to the authorized_keys file file in the .ssh/ directory in your home directory on the remote machine.
You can now ssh to the remote systems's account without the use of a password.Since this is such a common task, I created a shell script to handle it for me. This will create the local SSH key pair if it doesn't already exist, then copy it to the remote machine.
The last
ssh
command could be replaced withssh-copy-id
. I didn't do that because I wrote the program before I found out aboutssh-copy-id
and it's always worked well enough for me.When not using port 22 for ssh, change this line: ssh $1 "[[ -d .ssh ]]... to ssh '-p 3433' $1 "[[ -d .ssh ]]... (substitute 3433 for your ssh port id)
Great script!
Cheers, py