SFTP without passing the password

Hi All,

I am trying to do SFTP without passing the password.

I did it by generating the Key pair on both source and destination servers but the problem is My script is running with BATCHADM user whereas I am doing SFTP using another username (sftp user1@destinationServer) due to which it is prompting for password.
(whereas if I run my script using the same user as SFTP user, it won't ask for password.)

Thanks in Advance.

Regards,
Ranjeet

You could set up sudo to let you do the sftp with user A as user B so that the correct keys will be used.

Its giving me error

ksh: sudo: not found

If you have code can you please pass... I am using the below code for this:

$ ssh kaurr06@destinationServer  bash -c "echo mypass | sudo -c kaurr06"

It's giving 'not found' because there's no command named 'kaurr06'. Presumably that's a username?

While "echo mypass" is running, any user on the system may be able to see that plaintext. This is why you can't feed passwords into sudo automatically, it's specifically designed to prevent that for security reasons. This also applies to ssh and su. Better to get your keys working...

If batchadm can't get to your keys, creating a copy of the keys in a place batchadm has permissions to read could work.

Or better yet, give batchadm its own key.

Keys don't have to be in ~/.ssh/, you can specify an alternate location with -i. The folder they reside in must belong to the user in question and have 0700 permissions.

ssh -i /path/to/id_dsa username@host