I encrypted a text file in terminal using "gpg -c filename" and got "filename.txt.gpg" created in my file manager. I deleted the original unencrypted file.

Now I want to decrypt it in Nano so I can continue working on it. If, in a terminal, I do "gpg -d filename.txt.gpg", the file opens in terminal where I can read it, but do nothing else.

I want to open the encrypted file in Nano, and add data to the file in Nano.

I've tried every way I can think of, but not able to decrypt and open the file in Nano. Any ideas? Thx.

1 Answer 1


gpg -d just prints the file to standard output, but you can redirect the output to a file instead: gpg -d filename.txt.gpg > filename.txt. Or use the -o outputfilename option. Also, you can just run gpg filename.txt.gpg, which cause gpg to guess what you want, and in that case it decrypts the file to filename.txt (dropping the final .gpg).

Of course, note that when you decrypt the file on a regular filesystem, the OS may write it to the disk and removing the file afterwards will not clear remains of the file data from the disk. To avoid that, make sure to decrypt sensitive data only to RAM based filesystems.

On Linux, that would be the tmpfs filesystem. In some distributions, /tmp is a tmpfs by default. If it isn't, you can mount a new tmpfs simply with mkdir /ramfs; mount -t tmpfs tmpfs /ramfs (as root, change the ownership and permissions as required). Just mounting a filesystem doesn't mean that your files would be saved there, but a full discussion of safely handling sensitive data is outside the scope of this answer.

  • Thanks. The first way works, didn't try the "-o", but not the third way. The 3rd way just tries to re-encrypt the same file. But doesn't matter, first way works fine. After that, need to go into Nano and go to the file directory and open the NON-encrypted duplicate copy and edit text. Then save it via encryption and repeat if want to add more data or edit. Thanks again.
    – themira
    Jul 19, 2019 at 11:06
  • ...the one thing I don't like is that when I open the unencrypted file in Nano and go to edit, it doesn't contain the original file name and I have to retype the file name again; seems trivial, but would rather just save. Thanks again.
    – themira
    Jul 19, 2019 at 11:13
  • @themira, hmm, I have gpg 2.2.4 on Ubuntu, and gpg filename.txt.gpg gives gpg: WARNING: no command supplied. Trying to guess what you mean ... and then it asks for the passphrase and decrypts the file.
    – ilkkachu
    Jul 19, 2019 at 11:21
  • ~$ gpg ENCRYPTING.A.NEW.FILE.IN.NANO.gpg;;; gpg: AES encrypted data; gpg: gpg-agent is not available in this session; gpg: encrypted with 1 passphrase; File ENCRYPTING.A.NEW.FILE.IN.NANO' exists. - - Overwrite? (y/N);;; When I add the ".txt" ending, it does change the output. The first output above is without the extension. With extension ------------ gpg ENCRYPTING.A.NEW.FILE.IN.NANO.txt.gpg;;; gpg: can't open ENCRYPTING.A.NEW.FILE.IN.NANO.txt.gpg' :~$
    – themira
    Jul 19, 2019 at 11:29
  • In regards to your additional 'answer' notes, I am having trouble determining how to remove certain hidden files from the directory in Nano. The files are either locked or .swp. I think Nano created backups of them without me knowing it. If someone were to get on my computer, I do not want them to see the NAMES of any of my deleted files, regardless of content. Is this what you are referring to when you said to only decrypt to RAM filesystems, though you seemed to be more focused on the content, I'm guessing? Would you happen to know how to remove these items from the directory? Thanks.
    – themira
    Jul 19, 2019 at 11:41

You must log in to answer this question.

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