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!

programmatic sftp ing 4

Status
Not open for further replies.

philipose

Programmer
Dec 24, 2003
137
US
I am trying to sftp a file programmatically from an AIX server to another AIX server. I know the ip addresses of the 2 servers, logon ids and passwords on the 2 servers, file and folder to put files and files to get.

Can anyone help me out to implement this ?
Thanks a lot
philipose
 
Why not scp instead

#!/bin/sh

scp remoteuser@remotehost:/path/to/file.txt /path/to/local/target

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
You need to look at public/private keys
Try This link

Ceci n'est pas une signature
Columb Healy
 
Thanks Columb and Mike for your help. I tried out scp. I still need to put in the password manually for scp, right ? I did not understand Columb's direction, though.
Philipose
 
Philipose,

By exchanging rsa keys, scp is able to avoid using a password.

Follow columb's link (you can always do a search for "ssh without password" and see variations of these instructions).
 
Try this script, it will generate the keys and scp the key to the other server if all the rights are set up properly

#!/bin/ksh
# This creates the ssh keys for the user and exchanges them with the customers
# Servers

cd /home/$USER

touch test.txt
clear

test -e /home/$USER/.ssh/id_dsa.pub

if [ "$?" -eq "1" ]
then
echo "\nThis will generate your ssh keys"
echo ........
echo "\nJust hit enter 3 times when it asks you for a passphrase"

ssh-keygen -t dsa
fi

EX=1
while [ $EX = 1 ]
do
echo "\nPlease enter the customers' server you want to exchange keys with: \c"
read SRV

cd .ssh

ssh $SRV mkdir .ssh

cat ~/.ssh/id_dsa.pub|ssh $SRV "cat - >>.ssh/authorized_keys2"


#scp id_dsa.pub $USER@$SRV:

#cat ~/.ssh/id_dsa.pub | ssh $USER@$SRV "cat - >> ~/.ssh/authorized_keys2";chmod
600 .ssh/authorized_keys2

echo "\nTesting autologin by copying a file to $SRV"
cd /home/$USER

scp test.txt $USER@$SRV:

echo "\n\nDo you wish to exchange keys with another server? (y/n) : \c"
read ext
if [ "$ext" = "N" ] || [ "$ext" = "n" ]
then
EX=2
fi
done
 
normntwrk said:
echo "\nJust hit enter 3 times when it asks you for a passphrase"

<shudder>

Philipose,

It should be noted that this will allow anyone gaining access to $USER's account on your origin server to open a shell on the destination server without a password or passphrase.

If the files you're transferring are a limited set with non-variant names, I'd suggest picking up a copy of SSH The Secure Shell from O'Reilly and looking into "forced commands". With a little debugging with SSH_ORIGINAL_COMMAND you can determine exactly what commands would be executed on the destination server for your scp transfers, and then create a keypair for each command (this will make sense once you've read about keys and forced commands in the book).

- Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

A Simple Code for Posting on the Web
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top