I have the following script:

#!/bin/sh -e
echo before
echo $PWD | gpg --passphrase-fd 0 -c $file
echo after

The scripts works perfectly fine if executed manually, but simply stops working when the gpg line is performed when performed as crontab.

GPG shows:

gpg: cannot open `/dev/tty': No such device or address

I'm grateful for any suggestions!

Solution: add --no-tty to GPG

  • 3
    $PWD is very bad choice for a variable. it is a shell variable...
    – dfc
    Oct 18, 2011 at 22:00

3 Answers 3


Add -vv to the gpg command to see more output. It might have to do with a missing ~/.gnupg though.

  • 2
    Thank you, that pointed me into the right direction: --no-tty
    – MrG
    Oct 14, 2010 at 10:37
  • 2
    This is a good troubleshooting step as advice for everyone, but it seems that for a lot of people the real solution is --no-tty so this accepted answer could be improved if you turn the suggestion of a missing ~/.gnupg into a list and add --no-tty as a second item on that list.
    – greggles
    Dec 14, 2017 at 15:31
/usr/bin/gpg --no-tty --passphrase-file /home/vouuuuuuuuu/settings/passfile.txt --decrypt-files /home/juhuuu/dirname/*.gpg;
  • works fine now thank to --no-tty
  • before in cron job log gpg: cannot open/dev/tty': No such device or address`
  • so it could not execute before, now is fine!

To resolve this problem just add the "--no-tty" option to your gpg command line. answer was taken from a cached google page


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .