I would like to automate a bash script, that connects to server using sftp and does a file transfer. I have the password for this, and initially I tried for this
sftp $acc@$host << EOF
<passwd_here>
cd $dir
get $file
quit
EOF
but it still prompted for password, and I had to enter it manually at the prompt.
After searching SO, I found this post which had a solution with expect
, which I tried and I got the following error:
Script:
sftp -b cmdfile.txt $acc@$host
expect "Password:"
send "<passwd>\n";
interact
Error:
Permission denied (publickey,keyboard-interactive).
cmdfile.txt
cd $dir
get $file
quit
Please let me know, How to connect using the password in a bash script?
Yes key-based auth is the way to go. Check here for some direction.
With scp/sftp you should use key-based authentication. Public key from the user you want to authenticate copy into ~/.ssh/authorized_keys file on the server, into home directory of user on which you want log on. Storing password in clear text on client side is not a good practice, you know :) That way you "workaround" problem of reading password from the prompt too.
Please try the below steps