View Full Version : RCP -Remote file copy
kasunasanka
2007-03-05, 08:28 PM CST
Hi,
I want to automate the remote file copy
for that i have used RCP command but when i use RCP command to copy file from remote machine it asked password its ok if i copy manually. But i want to automate the process using crontab.Please help me to complete this process.
:confused: :confused:
stevea
2007-03-05, 08:55 PM CST
Try rsync
All the "r"command stuff (rsh, rlogin, rcp, ...) is pretty ancient and minimalistic.
kasunasanka
2007-03-06, 06:50 AM CST
I've used the rsync command s as follows
1.
rsync -e ssh -avz --stats --delete ops@152.222.200.3:/soft/software/rpms/test.rpm /test/copy.rpm --password-file /test1/rync.password
2.
rsync -e ssh -avz --stats --delete ops@152.222.200.3:/soft/software/rpms/test.rpm /test/copy.rpm --password-file=/test1/rync.password
but after that it asks to enter the password as follows,
ops@152.222.200.3's password:
I wan't to use rsync in cron job but because of the above problem I can't use rsync.
please help me to solve this problem.
:confused: :confused:
stevea
2007-03-06, 05:43 PM CST
Sorry for not including enough detail. Your task is still easy.
I was assuming (I should have said) that you set up an rsync server on the main repository
and then copy from/to with an rsync client.
=== to set up rsync daemon ==
On your file server/repository edit the /etc/rsyncd.conf file to include the "depot" directories like,
motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
use chroot = no
max connections = 10
timeout = 300
#hosts allow = <your list>
[universe]
path = /
comment = UNIVERSE on myserver
read only = no
list = yes
[common]
path = /home/depot
comment = COMMON on myserver
uid = root
gid = root
read only = no
list yes
Then to complete the server setup you must start the rsync daemon and arrange for it to start on every boot. start "system-config-services". Put a checkmark on "xinetd" if it's not already there, then (if not running) selects the "start" and "save" . The above just starts the mult-daemon xinetd.
To enable rsyncd select the "On Demand Services" tab, check the "rsync" box and save.
===
You can now access the "depot" like,
rsync -av myserver::common/ /home/local-dir # copy from myserver common depot
and
rsync -av /home/local-dir/ myserver::common/ # copy to myserver common depot
with no password request.
If security is an issue use the "hosts allow" and also look into /etc/hosts.deny, /etc/hosts.allow
=== === ===
Your attempt used "single-ended" rsync with ssh as the transfer mechanism. This can work too, but you must configure ssh to accept connections between trused hosts w/o passords. This is simple and you may prefer this solutions for several reasons. First it permits convenient ssh connections (I use these all the time between my home systems) and you can then either use "rsync -s ssh" and take advantage of rsync's higher efficiency of comparing and transferring diffs, OR you can just use "scp" with no password.
To use ssh without a password examine this
http://www.linuxhorizon.ro/ssh-wo-passw.html
The process is very simple. From the account you want to logon FROM (the client) use "ssh-keygen" to create both a private and public portion of a keypair (use no passphrase). And I'd suggest that you copy both files "id_rsa" "id_rsa.pub" to the directory ~/.ssh . You can make this directory if it doesn't already exist (mkdir ~/.ssh). To enable logins w/o pwords you must concatenate the public part ("id_rsa.pub") onto the end of the file ~/. ssh/authorized_keys on the server system and account.
For example you can copy your public key to the server system with
scp id_rsa.pub otheruser@myserver:/tmp/foo.pub
{you need a password this time}
Then on the system "myserver" you can concatonate the the public key "id_rsa.pub" onto the ~/.ssh/authorized_keys for every user where you might want to login.
cat /tmp/foo.pub >>/root/.ssh/known_hosts
cat /tmp/foo.pub >>/home/stevea/.ssh/authorized_keys
and so on.
From then on if you use ssh or scp or sftp from the client to the server (to one of the accounts that has the public key inserted), then no password will be requested. You could then do the whole cron script with "scp".
I hope this helps.
BTW the passwordless ssh acounts are quite useful & convenient for remote login.
pete_1967
2007-03-06, 05:56 PM CST
Or just go to your .ssh directory and `ssh-add [private_key_name]`, enter your private key password and you don't have to enter it unless you log out or reboot.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.