GPG Decrypt: Bad Session key / Variable Unset / Exclamation Mark
I am trying to decrypt a gpg file, but am continually getting the following error:
gpg: decryption failed: Bad session key
I realised afterwards that the gpg passphrase (which is set by a script) has an exclamation in it
passphrase="my!pass"
When setting via TTY, bash complains
-bash: !pass: event not found
When I echo the variable, it's unset.
user@host:~$ echo $passphrase
user@host:~$
So, the variable is unknown, and I assume that's why I can't decrypt my file.
I've tried the following as a password:
- my!pass
- my
- !pass
- 'my!pass'
- -bash: !pass: event not found
- bash: !pass: event not found
- -bash:
- bash:
- event not found
Fairly sure I've just learned a very painful lesson here, but it's worth a shot.
Can anyone help with:
- What does bash do with an unset variable if you try to use it?
- How does a script deal with an unset variable?
- Is there anything else I can try in place of the password?
- Is there an ASCII / UTF whitespace code that I can try in place of the password?
Solution 1:
There are a few comments worth noting.
- "... the gpg passphrase (which is set by a script)". I take it you didn't write the script. Please post the script. Are there any instructions to use it?
-
passphrase="my!pass"
. This doesn't mean "use ! as part of the string".!pass
means "read history, and get the last command starting withpass
". If there are no commmands in history starting withpass
, the errorbash: !pass: event not found
is raised, as you are getting at the command line. That's why I guess you didn't write the script. It is conceived for a case when there is some command in history starting withpass
. - "When setting via TTY (and I guess you executed
passphrase="my!pass"
), bash complains... When I echo the variable, it's unset". As mentioned above, an error is raised. But there are two more things happening: 1) The command is not executed. I.e., you don't even get "my" (you might have expected to get "my" = "my" + empty string) as the value ofpassphrase
, it keeps unset. 2) The command is not even added to the history.
As for some of your questions:
- What does bash do with an unset variable if you try to use it? bash typically replaces it by an empty string. But generally speaking, it depends on how it is used, it may raise errors, you may have a sentence that replaces its value by a default value in case it is not set, etc. There is no single answer for this.
- How does a script deal with an unset variable? Same as above.
I don't know about the rest of your problem, but this perhaps helps you understanding the issue and solving it.