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!

Using ssh in a shell script

Status
Not open for further replies.

weberm

Programmer
Dec 23, 2002
240
US
I am attempting to use ssh in a shell script but it requires someone to enter the password. Is there a way to set it up in a similar manner to
Code:
ftp -i < ftpscript
so that it gets the password without human intervention?
 
Yes, you want to use key pairs
my notes said:
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.
These keys allow connectiosn using ssh, scp and sftp as required.

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top