SFTP key authentication not working from bash script

0

I am trying to set up a very simple bash script on Ubuntu that SFTPs to a specific server using public key authentication. When I run the command directly on the command line, it works like a charm:

debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/xxx/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279

When I place the same command in a bash script and then run that script, the public key is not accepted and it goes to next authentications.

debug1: Offering RSA public key: /home/xxx/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: password,publickey,keyboard-interactive

The command I am trying to run is very straightforward, nothing fancy about it:

sftp -vvv user@domain.com

Any ideas of what is causing this?

D. Robles

Posted 2015-12-02T06:40:50.997

Reputation: 1

Not enough info on the client side, you should look at the logs server-side, and paste that info here. – MariusMatutiae – 2015-12-02T08:45:40.230

is the private key passphrase protected? Isn't it provided by ssh-agent? – Jakuje – 2015-12-02T17:53:57.167

Answers

0

Try to specify explicitly the path to private key file, using the -oIdentityFile=/path/to/id_rsa parameter

example :

sftp -oBatchMode=no -oIdentityFile=/home/username/.ssh/id_rsa -b - username@192.168.1.2 << !
   cd /directory
   put filename.txt
   bye
!

AleasterX

Posted 2015-12-02T06:40:50.997

Reputation: 1