Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of SCP in automated scripts

Status
Not open for further replies.

annay121

Programmer
May 3, 2005
11
US
I have a shell script using ksh which is supposed to transfer file from one Unix server to another using scp. The script is automated using Autosys. Have heard about some authentication public-private keys which would have to be used but am not clear on it.

Any help would be great.
Thanks
 
All you need is to have the +rhosts file on each server refer to each other.
 
To use public/private key pairs:

[ul]
[li]On source server: cd ~/.ssh ; ssh-keygen -t dsa -N "" (using DSA encryption as an example0, accept default filenames)[/li]
[li]scp id_dsa.pub destserver:.ssh/authorized_keys (where "destserver" is the name of the destination server, type password when prompted)[/li]
[/ul]

You should now be able to ssh and scp to the destination server without being prompted for a password.
If the .ssh directories don't exist, create them. Make sure they are owned by the user performing the scp, and that their mode/permissions are 700 (drwx------).

Annihilannic.
 
Using .rhosts is not the best answer. You should set up public private key pairs using
Code:
Un-attended login
When batch scripts require secure access to remote hosts, i.e. no user to type in the password, an un-attended-login is required. This is achieved by copying the requesting user's authentication key from the source host to the target host into a file called .ssh/authorized_keys. E.g. to set up an un-attended login for 'user' on host2 when connecting from host1: - 

user@host1> cd; mkdir .ssh
user@host1> ssh-keygen -t rsa -N '' -f .ssh/id_rsa
user@host1> scp .ssh/id_rsa.pub user@host2:user_host1_key #requires password
user@host1> ssh -l user host2 'mkdir .ssh; cat user_host1_key >> .ssh/authorized_keys' #requires password
user@host1> ssh -l user host2 'ls -la' #Does NOT require password
…


The ssh-keygen command generates the user's key for host1. Thus, when added to the authorized-keys file on host2 allows user on host1 to login into user account on host2 without entering interactive mode to enter the password, i.e. un-attended login.

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top