SFTP script still asking password

Hi All,
I have FTP script snippet

targetFTP=testcomp
userID=testid
userPass=XXXXX

server_availability ()
{
echo "***********************************************************" >> $FtpLog
echo "*         Server Availability & User Access Checks        *" >> $FtpLog
echo "***********************************************************" >> $FtpLog
ftp -vn $targetFTP <<EOF
user $userID $userPass
pass
bye
EOF
echo "***********************************************************" >> $FtpLog
}


transfer_file ()
{
echo "***********************************************************" >> $FtpLog
echo "*                    File Extraction                      *" >> $FtpLog
echo "***********************************************************" >> $FtpLog
ftp -vn $targetFTP <<EOF
user $userID $userPass
pass
bi
lcd $inputDir
cd $outputDir
pwd
mput fiedel-$TDATE*.csv
bye
EOF
echo "***********************************************************" >> $FtpLog
}

Now requirement is to transfer via SFTP due to security restriction.

  1. What I did I have generated Public key ssh-keygen and hosted that key to the target machine for password less authentication

  2. replace FTP as SFTP as below and run but still it is interactive.

  3. how i can make it non interactive so it will not ask password.

targetFTP=testcomp
userID=testid

server_availability ()
{
echo "***********************************************************" >> $FtpLog
echo "*         Server Availability & User Access Checks        *" >> $FtpLog
echo "***********************************************************" >> $FtpLog
sftp userID$targetFTP<<EOF
pass
bye
EOF
echo "***********************************************************" >> $FtpLog
}


transfer_file ()
{
echo "***********************************************************" >> $FtpLog
echo "*                    File Extraction                      *" >> $FtpLog
echo "***********************************************************" >> $FtpLog
sftp userID@$targetFTP<<EOF
pass
bi
lcd $inputDir
cd $outputDir
pwd
mput fiedel-$TDATE*.csv
bye
EOF
echo "***********************************************************" >> $FtpLog
}

scriptoutpt

$./test.sh
Thiscomputer system  is FOR OFFICIAL USE ONLY.
sysftp@testcomp's password:

You have to run the script as sysftp or whatever users have ssh-keys set correctly. Your script assumes one username it looks like to me.

Log on to the sysftp account and try the script. ( If your system has sudo you allow users by granting sudo access to run your script as sysftp. Nothing else, just that script. This usually is done on a group basis, but can be done for each user that needs the access. If this is the case, setup sudoers, then try using sudo to run the script instead of just logging on as sysftp)

In any case if you actually are a user with ssh-keys running the script:
If it asks for the password, you have not set up things correctly.

Common sources of error:
Check permissions on the local .ssh directory that should be in sysftp's login directory tree. Check permissions on the home directory of sysftp.

Here is a how to on setting up sftp (which means use the ssh protocol to login):
How To Setup SSH Keys on a Linux / Unix System � nixCraft

Where Jim says about checking permissions, you need to be aware that they should not be overly open so don't just go with chmod 777 ..... everywhere.

SSH and similar tools will check that the files are not readable by anyone other than the intended user, including the .ssh directory. Ideally, set permissions as rwx------ for the.ssh and rw------- for all the files within. The directory and files must be owned by the account running the sftp command.

I hope that this helps,
Robin