کد:
-pasword-file=/file.txt
---------- Post added at 07:04 PM ---------- Previous post was at 06:54 PM ----------
کد:
#
Identify the server that initially contains the files (we will call this the SOURCE server), and the serverto which you want to transfer the files (we will call this the TARGET server). Confirm that you can log in to the SOURCE server, that you can log in to the TARGET server, and that while logged into the TARGET server, you can use ssh to login to the SOURCE server using your password.
#
Step 2
Log into the TARGET server. Execute the command
[mikeular@targethost~]$ ssh-keygen -t dsa
ssh-keygen will ask you where you want to save the key. Accept the default directory, which will be ~/.ssh/id_dsa . Next it will ask you for a passphrase, leave this entry blank.
Your private key file will be saved to ~/.ssh/id_dsa and your public key will be saved to ~/.ssh/id_dsa.pub. Careful! Anyone who obtains a copy of your id_dsa file will be able to login to the SOURCE server as you, without authenticating themselves. Make sure that it's stored securely!
#
Step 3
Now you will configure the SOURCE server to accept the key. Once this step is complete, anyone with the id_dsa file will be able to log into the SOURCE server without providing a password.
Log into the SOURCE server and create the ssh directory:
[mikeular@sourcehost~]$ mkdir ~/.ssh
[mikeular@sourcehost~]$ cd ~/.ssh
Using vi or another text editor, create a file in ~/.ssh named authorized_keys2 . Now switch over to the TARGET server and copy the contents of the file id_dsa.pub and paste them into authorized_keys2 on the SOURCE server. Save the text file.
#
Step 4
Make sure that the authorized_keys2 cannot be changed by other users on the SOURCE server:
[mikeular@sourcehost~]$ chmod 644 ~/.ssh/authorized_keys2
#
Step 5
Now you can test your setup. Go back to the TARGET server and connect to the source.
[mikeular@targethost~]$ ssh username@sourcehost.com
[mikeular@sourcehost~]
Your ssh connection is now working correctly.
#
Step 6
Test your rsync over ssh connection by copying a file from SOURCE to TARGET. Enter the following command all on one line, being sure to substitute in the correct pathnames, username, and hostname.
[mikeular@targethost~]$ rsync -avz -e/usr/bin/ssh username@sourcehost.com:/home/username/testfile /home/mikeular/
This should copy the file "testfile" from your home directory on sourcehost to your home directory on targethost.
#
Step 7
All that's left is to setup your cron job. Plenty of documentation is available online.