Don Gould wrote:

I want to set up a script to move a file from one server to another using
ssh.

Can anyone point me to a template to do this?

I want to get cron to do this each day at 10:30pm (this bit I think I can
work out for my self :)

I just don't know how to automate ssh.

Cheers Don






You need to automagically authenticate yourself on the remote machine. Assuming you're going to do this as user1, you need to do the following steps:

1. On the machine that you're going to be copying from, generate public authentication keys

ssh-keygen -t dsa
( hit return to all of the queries about where to put the files, what phrase to use, etc. )


The important file that you've created is ~/.ssh/id_dsa.pub

2. Copy this file over to the target machine.

scp ~/.ssh/id_dsa.pub target:/tmp

This will ask you stuff about whether to add it to your list of known hosts, and get that bit of the setup done. answer yes to questions, and put in the password when requested.

3. ssh to the target server as user1.

4. If it doesn't exist, mkdir ~/.ssh
cat /tmp/id_dsa.pub >> ~/.ssh/authorized_keys
(append just in case there's stuff already there that you don't know about)


5. Test. log out back to the source machine, and ssh to the target. If you're not asked for a password, then you can also scp without needing a password.

hth,

Steve

Reply via email to