ssh and rsync without using passwords

Installing, Configuring, Troubleshooting server daemons such as Web and Mail
Posts: 1
Joined: 2012/02/22 22:06:41

ssh and rsync without using passwords

Postby Barjawi » 2012/02/22 22:20:13


I am creating cronjobs that backup the databases on the main server, and I want to copy these backups to a backup server. Of course, for this to happen, I have to get the rsync to work without entering passwords.

I have been looking for this for a while now... I have followed most of the tutorials online... but to no avail... not sure what I am doing wrong here. I hope I can find some answers here.

So this is what I do:

on the main server, I login as root, and then:
> ssh-keygen -t rsa

then I hit enter on all the questions (i.e., no password, and default location)

then I use the following command to copy the public key to the backup server:
> ssh-copy-id -i .ssh/

I made sure that the .ssh folder has 700 permission, and the private key as well as the authorized_hosts has 600 permissions.

but still whenever I use:
> ssh

I still need to enter my password.... what am I doing wrong here?

Now my next step after getting ssh to work without entering password is to use the following command on the main server in order to copy the backup files:

>rsync -alvz -e "ssh -i ~/.ssh/id_rsa" --cvs-exclude backup-files barjawi@myserver:path/to/location/

is that corrrect way to do it?

In addition to that, I also need to be able to pull data from the backup server without the need to enter passwords as well... do I need to reverse the operation in order to use such an rsync operation?

>rsync -alvz -e "ssh -i ~/.ssh/id_rsa" --cvs-exclude barjawi@myserver:path/to/location/backup-files .


User avatar
Forum Moderator
Posts: 20962
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: ssh and rsync without using passwords

Postby TrevorH » 2012/02/23 01:08:47

Since you generated the key and copied it as root, did you check the ownership of the ~/.ssh/authorized_keys file to make sure the user can read it?

Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America

Re: ssh and rsync without using passwords

Postby pschaff » 2012/02/23 02:37:40

Welcome to the CentOS fora. Please see the recommended reading for new users linked in my signature.

Is also running CentOS-5? Is SELinux Enforcing? If so, check the SELinux context:

Code: Select all

ls -alZ ~barjawi/.ssh