4

I can log in to my remote using ssh/sftp (without the -b option)

sftp root@192.168.7.2

But when I try

sftp -b commands.tmp root@192.168.7.2

I get

Permission denied (publickey,password).
Couldn't read packet: Connection reset by peer

Commands.tmp looks like this

ls
exit

Anything I am missing here ?

anujdeshpande
  • 313
  • 1
  • 5
  • 11

3 Answers3

4

I used shhpass to write the password no interactive and I needed to add -oBatchMode=no

sshpass -p PASSWORD sftp -v -oBatchMode=no -b FILE USER@SERVER
francescalus
  • 30,576
  • 16
  • 61
  • 96
2

If you are authentication with a password or an encrypted private key, you cannot use the -b with plain sftp. The sftp man says:

Since it lacks user interaction it should be used in conjunction with non-interactive authentication

You can for example use a passphrase-less private key together with the -b.


If you want to use password authentication, you need to use workarounds like sshpass. See:
How to run the sftp command with a password from Bash script?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
1

This worked for me

sshpass -p 'PASSWORDSTRING' sftp -v -oBatchMode=no -b deploy/production username@ipaddress

production file

put -rp /from-directory /to-directory
atazmin
  • 4,757
  • 1
  • 32
  • 23