I want a script to upload daily files using sftp. Unfortunately, the remote server doesn't support ssh keys (it's my customer's server and for some reason they can't or won't change it despite countless recommendations). So I need to somehow log in automatically using password authentication.
I found many different solutions (here on SO and elsewhere) but they all seem to use tools like sshpass
, spawn
, expect
, send
etc. Unfortunately my script is to be used on macOS and these tools aren't available there.
I fully realize it is NOT secure to use plaintext passwords in a script or on the command line. But using ssh keys is simply not an option at this stage.
So, is it possible to run sftp
from the shell and specify the password either on the command line in plaintext, or specify some argument with a filename that contains the password?
Addition: after @MartinPrikryl's comment I got sshpass
to work, by using brew install esolitos/ipa/sshpass
.
However now I found out this doesn't work properly when I use the -b batch.txt
parameter for sftp
to process a bunch of commands. The batches I'm processing are typically a bunch of get and put commands.
So this works:
sshpass -f MyPassword.txt sftp rocketnuts@example.com
(I am logged in and getting the sftp prompt)
But this does not:
sshpass -f MyPassword.txt sftp -b list.txt rocketnuts@example.com
I'm getting this error:
rocketnuts@example.com: Permission denied (password).
So apparently the way sshpass
sends the password to sftp
somehow interferes with the batch input from the -b
parameter.
Is there a way to make sshpass
(or another form of scriptable authentication) work in combination with the -b
option??