How to use passwordless sftp in script?

Hi

I am trying to do SFTP in shell script in such a way that it should not ask for password.

for this is use below script but it prompt for password. here I am not abled to understand where I am making mistake.

 
 #!/bin/bash
# SFTP TO remote server
USER="ITO"
PASSWORD="abcd@1234"
HOST="12.18.1.20"
sftp $USER@$HOST << EOF
$PASSWORD
cd LOG
put *.tar.gz*
quit
EOF
 

thx in advance

scriptor

You need to implement another authentication method, e.g. "public key authentication". Check man ssh , chapter "AUTHENTICATION".

1 Like

thx Rudic it works after "public key authentication".

here I have one more query that is
will sftp will not work as passwordless without doing "public key authentication". ?

if possible without "public key authentication". then please let me know.

How about the other authentication methods mentioned in man ssh ?

"interactive password authentication" means "password typed by a human being in realtime authentication" and no substitutes for human will do. This is intentional. It prevents the old-fashioned and very insecure habit of dropping important passwords in script files. No modern login method, be it ssh, su, or sudo, will accept passwords passed this way without severe coercion and exploitation.

The proper method for noninteractive authentication is passwordless, i.e. keys.

1 Like