LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   gpg decryption is wonky (https://www.linuxquestions.org/questions/linux-newbie-8/gpg-decryption-is-wonky-4175660883/)

Gregg Bell 09-13-2019 09:24 PM

gpg decryption is wonky
 
It's encrypting okay but when it comes to decryption

Code:

gpg filename.gpg
it's wonky. 90% of the time it returns this:

Code:

gpg RuleNumber1.png.gpg
gpg: WARNING: no command supplied.  Trying to guess what you mean ...
gpg: AES256 encrypted data
gpg: encrypted with 1 passphrase
File 'RuleNumber1.png' exists. Overwrite? (y/N)

and it gives me no password box and no decrypted file.

But sometimes it works properly.

And sometimes it decrypts the file without the password box!

Kind of scary. Any ideas?

scasey 09-13-2019 11:22 PM

That’s pretty clear...you didn’t give a command...
What were you trying to do? Decrypt? Then
Code:

gpg —decrypt filename
See man gpg

(Oh...you said you were decrypting, so just include the command)

Gregg Bell 09-14-2019 03:28 PM

2 Attachment(s)
Quote:

Originally Posted by scasey (Post 6036635)
That’s pretty clear...you didn’t give a command...
What were you trying to do? Decrypt? Then
Code:

gpg —decrypt filename
See man gpg

(Oh...you said you were decrypting, so just include the command)

Thanks Sean, but your command didn't decrypt the file. And was your command

Code:

gpg -decrypt filename
or

Code:

gpg --decrypt filename
?

(Seems to me you used an em-dash, not a hyphen or hyphens. Did you mean to do that?)

See "encrypt" attachment for what I was doing to encrypt and "decrypt" for what I was doing to decrypt.

But like I said doing it this was unreliable. Most of the time it didn't work and the some times it even worked without a passcode.

I did look over the man page but there seemed to be multiple ways to encrypt and it was confusing. So what's the simplest way to encrypt and decrypt a file?

Thanks.

scasey 09-14-2019 03:41 PM

That was dash dash...Safari is messing it up.

See man gpg2 — command is always required

Quote:

--encrypt
-e
Encrypt data. ...

--decrypt
-d
Decrypt data

Gregg Bell 09-14-2019 08:43 PM

Quote:

Originally Posted by scasey (Post 6036789)
That was dash dash...Safari is messing it up.

See man gpg2 — command is always required

Thanks but I'm still not getting it. Is the encrypting:

Code:

gpg -e filename
?

Because when I do that, I get this:

Code:

gpg -e fireman.png
You did not specify a user ID. (you may use "-r")

Current recipients:

Enter the user ID.  End with an empty line:


scasey 09-14-2019 09:03 PM

Keys are associated with a user. You need to specify which user.
Note: I don’t know the answers...I’m just reading the man page. Another option is to search the web for the error.

berndbausch 09-14-2019 09:16 PM

The way I see it:

Before you can encrypt a file, first set up keys for a user, for example gpg --generate-key. You will be asked for name, email address, passphrase. Keys are stored in $HOME/.gnupg.

To encrypt a file, gpg -r USER -e myfile, where USER is name or email address provided in the key generation step. The encrypted file is named myfile.gpg.

To decrypt the file, gpg -d myfile.gpg. This asks for the passphrase and writes the decrypted content to stdout.

EDIT: When you leave out the command (--decrypt, --encrypt, --generate-key etc), gpg is supposed to guess what you want. Therefore, Gregg Bell's original command should figure out that the input file is encrypted and should automatically decrypt it. I don't have information (or experience, to be honest) to understand what makes it fail, but personally, I feel more confident when I tell the computer exactly what it should to rather than relying on heuristics.

The GPG manual documents options and helper tools like gpg-agent, but it misses a "first steps" section and doesn't seem to cover typical workflows. There are a number of tutorials on the internet, though. When the official documentation of a tool is lacking, I tend to check whether there is something on the Archlinux wiki or in the DigitalOcean tutorials. Both web sites have high-quality content in my opinion.

scasey 09-14-2019 09:31 PM

^^My guess is that the OP had missed the step of creating keys...I certainly didn't see that requirement until my upteenth pass through the man pages...and even then, not being interested in doing it myself, didn't even look to see how to do that step.
Definitely a lot of manual to read.

Excellent, well-focused post, berndbausch (As usual)

Gregg Bell 09-15-2019 12:40 PM

2 Attachment(s)
Quote:

Originally Posted by berndbausch (Post 6036846)
The way I see it:

Before you can encrypt a file, first set up keys for a user, for example gpg --generate-key. You will be asked for name, email address, passphrase. Keys are stored in $HOME/.gnupg.

To encrypt a file, gpg -r USER -e myfile, where USER is name or email address provided in the key generation step. The encrypted file is named myfile.gpg.

To decrypt the file, gpg -d myfile.gpg. This asks for the passphrase and writes the decrypted content to stdout.

EDIT: When you leave out the command (--decrypt, --encrypt, --generate-key etc), gpg is supposed to guess what you want. Therefore, Gregg Bell's original command should figure out that the input file is encrypted and should automatically decrypt it. I don't have information (or experience, to be honest) to understand what makes it fail, but personally, I feel more confident when I tell the computer exactly what it should to rather than relying on heuristics.

The GPG manual documents options and helper tools like gpg-agent, but it misses a "first steps" section and doesn't seem to cover typical workflows. There are a number of tutorials on the internet, though. When the official documentation of a tool is lacking, I tend to check whether there is something on the Archlinux wiki or in the DigitalOcean tutorials. Both web sites have high-quality content in my opinion.

Thanks very much, berndbausch. I will give this a try. And I guess the simple way of doing it just doesn't work? (It used to seem to.) See attachments. And they're from https://www.cyberciti.biz/tips/linux...-password.html

As it is, I think I'm going to get rid of the encrypted files I have (created with the above method) because some of them get opened without requiring passwords.

scasey 09-15-2019 04:39 PM

I note this at the bottom of the posts in the link posted in #9
Quote:

This did not work for me. It encrypted the file alright, but when I typed ‘gpg ‘ it decrypted the file without my typing in the password. What good is that?

j says:

it’s using your key, use a different account and you will need the password
Might that be your issue as well?

Gregg Bell 09-16-2019 12:10 PM

Quote:

Originally Posted by scasey (Post 6037054)
I note this at the bottom of the posts in the link posted in #9

Might that be your issue as well?

Thanks Sean. I think I don't know enough of the basic terminology and the way things work.

My latest sticking point is (I was following berndbausch's advice) when I got to the passphrase step I ran into this:

Quote:

We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy.
I didn't know what to do with that. Just put in a password? Or do all the other stuff?

berndbausch 09-16-2019 04:41 PM

Help the kernel generate random data by doing random things as described.

If your computer is a virtual machine, install haveged to speed up the random number generation process, otherwise it can take minutes or hours to accomplish this step.

Gregg Bell 09-17-2019 07:09 PM

Quote:

Originally Posted by berndbausch (Post 6037385)
Help the kernel generate random data by doing random things as described.

If your computer is a virtual machine, install haveged to speed up the random number generation process, otherwise it can take minutes or hours to accomplish this step.

Thanks for replying, berndbausch. :)


All times are GMT -5. The time now is 08:38 AM.