Ubuntu: How do I encrypt/decrypt file within gedit?


In the previous version of Ubuntu (eg: maverick, natty), I used to do a:

sudo apt-get install gedit-plugins seahorse  

to have the ability to encrypt/decrypt file within Gedit after enabling the plugin in the preferences.

But since, Oneiric I've not found a way of achieving this.

And now that I'm running Precise (the LTS version!), I'm a bit disappointed of not being able to do such things.


I had to fight a bit with ryran's example until I got what I needed: encrypt using my GPG key to several people. This is the code to encrypt:

#!/bin/sh  gpg -a -e -r test@test.com -r test2@test.com --no-tty -  

And to decrypt:

#!/bin/sh  gpg -d --no-tty - 2> /dev/null  

And set input to "current document" and output to "replace current document" in both cases.


Try Geany, with the PGP plugin. Geany is a lightweight gtk+ based editor, with excellent support.

sudo apt-get install geany geany-plugin-pg  


Some autopromotion/request for feedback: http://pietrobattiston.it/gedit-crypto

(notice I developed this also because I was not able to use the "External tools" method above without including in clear the password for my key - which I didn't want to).


Another one that uses the agent and supports entering E-Mail for asymmetric encryption:

#!/bin/bash    mail=$(zenity --entry --text="Enter E-Mail")  gpg -a -e --no-tty -r "$mail" --use-agent -  

And decryption:

#!/bin/bash    gpg --no-tty --use-agent -  


Pipe's link (in the comments) gives the run-down.
You need to add entries under "Manage External Tools" to do this.. for now. You can even add keyboard shortcuts. What the link doesn't mention (as far as I saw) is that you need to install gnupg-agent to be able to enter passphrases.

Here's an example. Create a new action and call it symmetric encrypt:

gpg --use-agent --symmetric 2>/dev/null  

Tweak the other options to your liking (you can make it so all the text in the whole window is automatically selected and replaced, you can make the output pop up in a bottom pane, etc.

Note: If you install gnupg2 instead of gnupg-agent, and then start your command-lines with gpg2 instead of gpg, you can take advantage of gpg2's cooler [integrated] agent.


Just expanding on @Ignacio solution (which works), I found annoying that if you encrypt twice (or decrypt), it breaks things... so I am running this with an extra care for the state of the encryption on the document:


#!/bin/bash  stdin=$(cat)    if [ ! "${stdin:0:27}" == "-----BEGIN PGP MESSAGE-----"  ]; then       echo "$stdin" | gpg -a -e -r email@email.com --no-tty -  else      echo "$stdin"  fi  


#!/bin/bash  stdin=$(cat)    if [ "${stdin:0:27}" == "-----BEGIN PGP MESSAGE-----"  ]; then       echo "$stdin" | gpg -d --no-tty - 2> /dev/null  else      echo "$stdin"  fi  

Assuming the settings:

  • Save - Nothing
  • Input - Current document
  • Output - Replace current document
  • Applicability - All documents / All languages

Then you place a shortcut like Ctrl+Shift+D (decrypt) and Ctrl+Shift+E (encrypt), and you are good to go.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »