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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SFTP

Status
Not open for further replies.

mediation

Technical User
Nov 11, 2006
17
Hi All,

We are in the process of changing our File transfers to Secure mode using SecureShell.
We already have scripts to Do File transfer using FTP client (i.e, non secure mode) and
iam giving one example, which explains how we automate regular FTP.

Now we are changing all of them to SFTP or Secure transfer mode/encrypted.

Our old regiular scripts are some thing like this


ftp -n -i -v ftp.url.com <<!
user username password
cd /data/shared/
lcd /data/import
mget vcm*.dat
bye
!
My question is

How to Automate the SFTP Scripts by passing Password through the script.

Responses are highly appreciated.

Thanks in advance,
 
you can do the same using scp using ssh version 2 and dsa key exchange.

have a look to the man page of scp, you'ill be able to use your existing scripts just with small modifications.

For key exchange auth have a look to your sshd_config file specificaly to those lines:

PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys


generate your dsa key with ssh-keygen -t dsa

and copy your public key to the authorized_keys file of the distant user on the box you want to connect to.

 
To expand from Gloup's commnents
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.
The same mechanism works for ssh, scp and sftp.

However, the permissions on home directories is important for this to work. In particular, if user2 on host2 has global read on thei home directory it will not work.

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

Part and Inventory Search

Sponsor

Back
Top