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 email@example.com
Any ideas of what is causing this?
Try to specify explicitly the path to private key file, using the -oIdentityFile=/path/to/id_rsa parameter
sftp -oBatchMode=no -oIdentityFile=/home/username/.ssh/id_rsa -b - firstname.lastname@example.org << ! cd /directory put filename.txt bye !