SFTP prompting for password even though password is in script

Hi All,

I am trying to transfer a file from one server to a remote server using SFTP. Client is not ready for key setup.
I am working on Solaris 10.
Here is the code.

#!/bin/ksh
# sample automatic Sftp script to dump a file
USER="user1"
PASSWORD="pass1"
HOST="host1"
sftp $USER@$HOST << EOF
$PASSWORD
cd dir1
put file1
quit
EOF

But its prompting for a password and I want to bypass entering a password.
Please let me know how can I avoid entering the password when I run the script.

Thanks
Megha

ssh and scp and sftp are designed to prevent you from doing what you're trying to do, because keeping passwords in scripts is an extremely bad idea. "interactive password authentication" means "password typed by a human being in realtime authentication", and no substitutes for humans are acceptable to ssh.

The proper way to login noninteractively is to arrange ssh keys in advance.

Look here:
sftp prompting for password | Unix Linux Forums | UNIX for Dummies Questions & Answers

Ho Corona668,

Thank you for the reply . I followed the steps in the article that you mentioned to the point where I must run the command

ssh-copy-id -i ~/.ssh/id_rsa.pub username@mystery

But I get ssh-copy-id not found.

SO i tried to follow the work around step
edit the file

/etc/sshd/sshd_config

Now i am getting /etc/sshd not found.
Could this be a permissions issue ?
Please let me know.

Thanks
Megha

It doesn't say to do that if you don't have ssh-copy-id, it says to do that if your server doesn't support that kind of authentication. It's a good thing you didn't manage to do so!

If you don't have ssh-copy-id you can copy the key manually:

cat ~/.ssh/id_dsa.pub | ssh user@remote.machine.com 'cat >> .ssh/authorized_keys'

Hi Corona688,

I did the

cat ~/.ssh/id_rsa.pub | ssh user@remote.machine.com 'cat >> .ssh/authorized_keys2'

when prompted for the remote machine's password, I keyed in the password.
But it appears that I am unable to do so; the system just hangs and I ultimately get a disconnect from the remote machine.

Does this mean I dont have access to add this public key ?

Thanks
Megha

If you don't get an error message when you disconnect, it may actually be working. It wouldn't print any messages.

If you didn't have access to something it would tell you 'permission denied'.