I'm baffled by an SFTP shell script and any help would be greatly appreciated. I wrote an sftp script to connect to and upload ACH information to a banking site. The script uses 'expect' to wait for responses from the remote site. The script runs on a RedHat server, release 5.11.

If I run this script from my home directory or my temp directory, the remote host responds to the login with "Password:" and my SFTP script runs normally. If I run this script from a directory dedicated to storing shell scripts that are used by CRON, the remote server responds with "Enter passphrase for key '/prod/apps/xxxxxx/batchjobs/ACRO_privatessh'" and my SFTP script hangs, as the expected response does not match what is sent from the remote server.

All other pieces except the directory from which the script is run, remain equal. This includes permissions, ownership, and the userId that executes the script. Put another way, I can execute the script from our batchjobs directory, where it hangs because the server response is 'wrong'. I can then copy that script to my home directory, and the script executes and completes because the server response is 'right'.

Thanks in advance for any help.


  • 1
    The script is using a different ssh key in the other setup. See if you can use a key that does not use a passphrase. What's different about your environment and the "deploy" environment? Oct 16, 2015 at 21:32
  • Glenn - Thanks for the quick response and the hint. There is a command in the script to set SFTPKEY based on the directory - SFTPKEY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/ACRO_privatessh" Am I correctly understanding that the key is tied (somehow) to the directory from which I am running the script? If so, is there a way to delete or disable the key?
    – Dan P
    Oct 16, 2015 at 22:23

1 Answer 1


When you run the script from your homedir, a temp dir, or elsewhere, the contents of $SFTPKEY is invalid (read: does not point at valid privkey), and therefore is not used. When you run it from it's "usual" home, the script finds /prod/apps/xxxxxx/batchjobs/ACRO_privatessh and attempts to use it. "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) outputs the name of the directory in which the script is located.

You have a couple of options:

  • use the key, either by modifying the script to allow you to enter the key's password; or by using ssh-agent; or by using a passwordless key.
  • remove references to $SFTPKEY from the script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.