Operating System - HP-UX
1833847 Members
2066 Online
110063 Solutions
New Discussion

Want to automate SCP transfers

 
SOLVED
Go to solution
John O'Neill_6
Regular Advisor

Want to automate SCP transfers

Hi all,

I am now wanting to use a script to automate transfer of database afer image files from my production machine to dr machine.

Since both systems have SSH installed i figured i'd use SSH, but SCP always requires a password to be entered, even if is in a script.

So, from what i've learned today.. I need to 'generate keys' which will somehow make this work.

OK, here's my setup:

TWO HP UX machines

prod <- production box
prodbk <- production backup box

I have a user account called 'Bob' on the prod box who wants to send a file to user 'Fred' on the prodbk box via SCP.

I want to be able to put the following command in a script:

scp testfile1.txt Fred@prodbk:/dbase/repldst/testfile1.txt

Without having 'scp' come back and ask for a password.

I'm after really simply basic baby step instructions here, i've tried to look at other threads but they often have very complicated examples.

Any help is once again most appreciated.

-John
9 REPLIES 9
Suraj K Sankari
Honored Contributor

Re: Want to automate SCP transfers

Hi,

Not clear about your question.
what you want file should go into prodbk without passwd and using fred login ?

Suraj
Steven Schweda
Honored Contributor

Re: Want to automate SCP transfers

A Forum search for keywords like
ssh passwordless
should find any number of old threads which
cover this.
Suraj K Sankari
Honored Contributor

Re: Want to automate SCP transfers

hi again,

here is the steps to login without passwd
login with Bob into prod server go to /home/Bob/.ssh

Bob@prod $ ssh-keygen -v -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (.ssh/id_rsa): press return key
Enter passphrase (empty for no passphrase): press return key
Enter same passphrase again: press return key

Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
2d:47:41:2d:5e:89:e7:10:85:31:36:f8:e6:e2:d4:23

Bob@prod $ cat id_rsa.pub >authorized_keys

Bob@prod $ Fred@prodbk:/home/Fred/.ssh/.

now you can scp, ssh without passwd into prod to prodbk server.

Suraj

Ganesan R
Honored Contributor

Re: Want to automate SCP transfers

Hi John,

Ok. Understood your requirement. As you understand, you need to setup SSH password less login between those two users. Follow the below instructions.

1.Login to Prod server as Bob user.

2.$ssh-keygen -t dsa
Press enter for all the questions.It will create the private/public key files under $HOME/.ssh/
File names are id_rsa and id_rsa.pub

3.Now you need to copy the id_rsa.pub file content into Fred's $HOME/.ssh/authorized_keys file on prodbk server
Prod#scp ~Bob/.ssh/id_rsa.pub Prodbk:/tmp

Login to Prodbk server

Prodbk#cat /tmp/id_rsa.pub >> ~Fred/.ssh/authorized_keys

Make sure the following permissions on Prodbk server.

Home directory should have 755 permission (Fred's home directory)
$HOME/.ssh directory should have 700 permission
$HOME/.ssh/authorized_keys file should have 600 or 640 permission


That's it. Now you can scp without password and automate the transfer
Best wishes,

Ganesh.
T G Manikandan
Honored Contributor

Re: Want to automate SCP transfers

http://saikrishbe.wordpress.com/2007/01/19/remote-login-without-password/

I would also check at rsync which can be used with SSH for automated process.

rsync -avre ssh filename fred@:/filename
Bill Hassell
Honored Contributor

Re: Want to automate SCP transfers

A couple of things to note concerning the public key that you append to .ssh/authorized_keys:

- The key is very long. Either append using something like cat id_dsa.pub >> .ssh/authorized_keys, or if you use vi, be sure to turn off ai and set wm=0 (hint :set noai wm=0). Then use wc on the authorized_keys file to make sure there is a single line per key.

- .ssh permissions must be 700, the files under .ssh should be 600.

The public key is generated on your local system, and copied to the userID's home directory on the remote system.


Bill Hassell, sysadmin
John O'Neill_6
Regular Advisor

Re: Want to automate SCP transfers

WoW, thanks everyone for all these very helpfull replies :)

I'll give it a shot and post back here letting you know how it all went.

-John
Steven E. Protter
Exalted Contributor
Solution

Re: Want to automate SCP transfers

Shalom,

Try this document:

http://www.hpux.ws/?p=10

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
John O'Neill_6
Regular Advisor

Re: Want to automate SCP transfers

Thanks everyone!

Problem solved, had some help at this end too.

Much appreciation once again!

Regards

John O'Neill

p.s. Points assigned.