noninteractive SFTP

Hi All,

need help.

i am doing one SFTP and now need to automate that.
how can i achive it with non interactive mode?

SFTP user@172.*.*.*

then it is asking for password.
after providing that its getting connected.

can you please help me so that i can give the password at a go and it does not ask for password again?

thanks

NIL

You need passwordless SSH login. You need to generate a public key using the ssh-keygen utility for your machine you use to do remote login and upload the key to the remote machine.

I think one is to use a public key authentication. This will provide password-less authentication as long as you client's public key is made the authorized on the server.

However I am not sure if you have control over the SFTP server.

Another option is to use "expect" script.

-Raja

hello raja,

the SFTP server is under control..

even i can do SFTP but giving the password when it prompts.
i need to bypass that prompt.

---------- Post updated at 01:02 PM ---------- Previous update was at 12:49 PM ----------

hello kevin,

i have issued ssh-keygen

Generating public/private rsa key pair.
Please be patient.... Key generation may take a few minutes
Enter file in which to save the key (/portal_home/pin/.ssh/id_rsa): nil
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in nil.
Your public key has been saved in nil.pub.
The key fingerprint is:
e0:ca:42:60:2a:09:52:f7:3

now can you please help me how to upload the key on remote machine?

I hope you didnt enter a passphrase while generating the public key. Else it will prompt for a passphrase instead of password.

Copy the contents of nil.pub to ~/.ssh/authorized_keys file in the destination system (sftp server). Please note that the key is one single line and ensure this while copying.

You can test it by ssh to the server and it should get you in without the password.

-Raja

hello Raja,

i didnt enter anything in passphrase.
~/.ssh/ in this location i can see a file known_host.
authorized_keys is not there.. should i create it and then paste?

Niladri

Yes. Please create a file authorized_keys and copy the public key.

On the safer side, make a copy of this file as authorized_keys2 on the same directory.

hello raja,

i am runnnig my code in X and will SFTP Y
i have generated the nil.pub in X and copied that (in one line) to the authorized_keys on Y.

now sitting in X when i am giving the command sftp Y, its asking for password again.
am i missing something?!

please help.

thanks
Niladri

I am not sure why it fails...probably try with a dsa key and ssh2
On X, run...

 ssh-keygen -t dsa

Copy the key from ~/.ssh/id_dsa.pub (on X) to the ~/.ssh/authorized_keys2 on the remote host.(on Y) (Note the filename now is authorized_keys2)

Ensure authorized_keys2 is not writable by group and others i.e

chmod go-w ~/.ssh/authorized_keys2 

-Raja

thanks a lot raja..
its done....
thanks again...

actualy in my case probably DSA keygeneration was also needed.
"ssh-keygen -t dsa"
i incorporated this also and it worked.

thanks a lot
cheers :slight_smile: