5

I use this command to check whether gpg password is valid or not:

gpg -o /dev/null --local-user $KEY_ID -as <(echo 1234)

This is a hacked command to check gpg password that I posted here. I can see that the /dev/null file permission changed from 666 to 644 and sometimes it become corrupted and some scripts are not able to write to /dev/null:

I can fix this by recreating /dev/null using the following command:

rm -f /dev/null; mknod -m 666 /dev/null c 1 3

1st question is, how do I prevent the /dev/null permission change or the file become corrupted when running the command so I don't have to manually recreate the /dev/null.

2nd question (if the 1st question does not have solution): How do I verify in bash whether the /dev/null file is corrupted or not? I want to use this method to recreate /dev/null as the last resort.

Any idea ?

MaXi32
  • 403
  • 2
  • 12

1 Answers1

2

man gpg looking at the effect of the -o parameter :

-o file Write output to file. To write to stdout use - as the filename.

Therefore, the command you issue creates an ordinary file named /dev/null with your default permissions.

In other words, issuing this command, you override the c in the crw-rw-rw permissions meaning its original definition as a character special device, rendering it totally useless regarding its original purpose.

In order to achieve trouble-free what you are willing to do, and as specified in the man, you should definitely use the hyphen (-) as the filename.

Then, as with any other *ux command, feel free to redirect the standard out to /dev/null. (>/dev/null)

Vlastimil Burián
  • 27,586
  • 56
  • 179
  • 309
MC68020
  • 6,281
  • 2
  • 13
  • 44
  • I thought GPG would redirect all output to /dev/null by using that. I fixed this using different command: `gpg --export-secret-keys -a $KEY_ID > /dev/null`. Thanks. – MaXi32 Sep 02 '20 at 17:50
  • I'm looking for alternative answer because the command I just posted previously was used by many people here: https://stackoverflow.com/questions/11381123/how-to-use-gpg-command-line-to-check-passphrase-is-correct. So, I think maybe this is bug from gpg because it treated the -output that way. If no answer is better, I would accept this. – MaXi32 Sep 02 '20 at 18:03
  • 1
    @MaXi32 : Instead of your command listed in your first comment above, and strictly according to the man : gpg -o - ...blahblah... > /dev/null – MC68020 Sep 02 '20 at 18:15