If you call GPG without input, it just says

gpg: Go ahead and type your message ...

You can enter text and everything, but how do you end the input? I've seen something like this in multiple different programs, but I've never known how.


You need to input EOF (End Of File). Do this with CTRL+D (or more generally, ^D).

  • Thanks! I had tried a number of things, including typing EOF. – IBPX Nov 20 '15 at 1:02
  • Also, is there a way to delete a newline in this input? As in, having pressed Enter, doing a "backspace" as you would in a regular editor? – IBPX Nov 20 '15 at 1:05
  • 1
    @IBPX I don't think it is possible to delete new lines in this situation. However, I am not 100% sure. – nehcsivart Nov 20 '15 at 1:11
  • 2
    @tchen No, it is not possible. This is because pressing return causes what you've typed so far to be flushed into the input buffer of the program (or file, or whatever keyboard input happens to be connected to)—once that happens, it's likely that the program is already operating on it (or that it's already being written to the file, or…), so there isn't an easy way to undo it. – Blacklight Shining Nov 22 '15 at 1:18
  • 2
    @tchen Fun fact: pressing control-d actually also flushes input in the same way. Pressing it when you've just flushed (either with control-d or with return) still flushes, only it flushes zero bytes (making the read() system call return 0), which is how the system communicates that the end of a file has been reached. Sometimes (usually not, but sometimes!), a program will keep reading even after it's gotten the end-of-file indication. Off the top of my head, gnutls-cli does this when you pass --starttls. – Blacklight Shining Nov 22 '15 at 1:22

Without any flags, gpg assumes you want to decrypt, expects an encrypted message, and will output the results, in binary, to stdout.

If you want to encrypt something and deal with the result in a practical way, try gpg -ea and then type some secret message, then cntrl-d and give recipients, when asked.

You can then copy the ascii-armored message to the clipboard which you can paste into a file or whatever.

If you relauch gpg without flags and paste that message in, it will ask for recipient's key passphrase, and then wait for you to close stdin... type ctrl-d and your message will be decrypted to stdout

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.