Add link to Org Babel section from Worg main page
[Worg.git] / org-tutorials / encrypting-files.org
blob155115c1f9c6d00e0f028a298fe9ff2242e9a316
1 #+OPTIONS:    H:3 num:nil toc:2 \n:nil @:t ::t |:t ^:t -:t f:t *:t TeX:t LaTeX:t skip:nil d:(HIDE) tags:not-in-toc
2 #+STARTUP:    align fold nodlcheck hidestars oddeven lognotestate
3 #+SEQ_TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
4 #+TAGS:       Write(w) Update(u) Fix(f) Check(c)
5 #+TITLE:      Encrypting org Files.
6 #+AUTHOR:     Ian Barton
7 #+EMAIL:      ian at manor-farm dot org
8 #+LANGUAGE:   en
9 #+PRIORITIES: A C B
10 #+CATEGORY:   worg
12 {Back to Worg's index}]]
14 * General Information About Encrypting Files with Emacs.
15 Emacs uses EasyPG as an interface to gnupg. If you have a recent
16 version of Emacs (at least 23) EasyPG is part of Emacs. However,
17 several package managers include a version of EasyPG for use with
18 earlier versions of Emacs. If your version of Emacs comes with EasyPG,
19 don't install the EasyPG package, as this will lead to conflicts.
21 To set up Emacs for transparent encryption and decryption our need the
22 add the following to your .emacs:
24 #+BEGIN_SRC emacs-lisp
25    (require 'epa-file)
26    (epa-file-enable)
27 #+END_SRC
29 * Encrypting the Whole File Using EasyPG.
30 If you want to encrypt the whole file using gnupg, but still have the
31 decrypted file recognized as an org file, you should make:
33 B-*- mode:org; epa-file-encrypt-to: ("me@mydomain.com") -*-
35 the first line in the file. Where "me@mydomain.com" is the email
36 address associated with your default gnupg key. Note that gpg
37 encrypted files should be saved with the default extension of .gpg.
39 When you open the file you will be prompted for your password and
40 Emacs will display the decrypted contents in org-mode. When you save
41 the file it would automatically be encrypted.
43 * Symmetric or Public Key Encryption.
44 If you use symmetric encryption all that is required to
45 encrypt/decrypt your file is the pass phrase. Using Public Key
46 Encryption, you require both your private key and your pass phrase.
48 EasyPG can use both methods of encryption. If you want to use
49 symmetric encryption omitting the "epa-file-encrypt-to:" from your
50 .gpg file should do the trick. If this doesn't work, you may try
51 setting the variable:
53 #+BEGIN_SRC emacs-lisp
54   (setq epa-file-select-keys nil) 
55 #+END_SRC
57 Conversely, if you want to use Public Key Encryption make sure that
58 you specify "epa-file-encrypt-to: " at the beginning of your file.
60 * Encrypting Specific Entries in an org File with org-crypt.
61 If you just want to encrypt the text of an entry, but not the
62 headline, or properties you can use org-crypt. In order to use
63 org-crypt you need to add something like the following to your .emacs:
65 #+BEGIN_SRC emacs-lisp
66 (require 'org-crypt)
67 (org-crypt-use-before-save-magic)
68 (setq org-tags-exclude-from-inheritance (quote ("crypt")))
69 ;; GPG key to use for encryption
70 ;; Either the Key ID or set to nil to use symmetric encryption.
71 (setq org-crypt-key nil)
72 #+END_SRC
74 Now any text below a headline that has a :crypt: tag will be
75 automatically be encrypted when the file is saved. If you want to use
76 a different tag just customize the "org-crypt-tag-matcher" setting.
78 Preventing tag inheritance stops you having encrypted text inside
79 encrypted text.
81 To decrypt the text just call "M-x org-decrypt-entry" and the
82 encrypted text where the point is will be replaced with the plain
83 text. If you use this feature a lot, you will probably want to bind
84 "M-x org-decrypt-entry" to a key.
86 Entries with a :crypt: tag will be automatically be encrypted when you
87 save the file.
89 If you have autosave turned on and decrypt the files encrypted
90 entries, the autosave file will contain the entries in plain text. For
91 this reason your should disable autosave for encrypted files.
93 * Using gnupg-agent to Cache Your Passwords.
94 If you need to decrypt files frequently, you will probably get fed up
95 of typing in your password each time you open an encrypted file. You
96 can use gpg-agent to cache your passwords, so you only need to type
97 your password once. Obviously this has security implications and it's
98 up to you to decide whether you want your passwords cached.
100 On Debian based systems your can install gpg-agent using your
101 package manager:
103 #+BEGIN_SRC sh
104   sudo apt-get install gpg-agent
105 #+END_SRC
107 You can configure gnupg-agent by editing ~/.gnupg/gpg-agent.conf. As a
108 minimum you will probably want to set:
110 - default-cache-ttl the time the cahse entry is valid in seconds. The
111   default is 600.
112 - max-cache-ttl the maximum time a cache entry is valid in
113   seconds. After this time the cache entry will be expired even if it
114   has been accessed recently.
117 To ensure that gnupg uses gnupg-agent you should edit
118 ~/.gnupg/gpg.conf and make sure that the use-agent line is
119 un-commented.
121 If you are using a console based system you need to:
123 #+BEGIN_SRC sh
124   eval $(gpg-agent)
125 #+END_SRC
127 in your shell's startup script.
129 If you are using a window manager you will probably want to install
130 one of the pin entry programs, such as pinentry-gtk2 or pinentry-qt,
131 so that X can prompt you for your pass phrase.
134 Now when you try to open a .gpg file, or decrypt some text encrypted
135 with org-crypt, you will be prompted for your pass phrase, but your
136 password will be cached so re-opening the file, or decrypting another
137 region will not prompt you for your password again.
139 * Emacs Backup Files - a Warning.
140 With org-crypt, if you have autosave turned on and decrypt the
141 entries, the autosave file will contain the entries in plain text. For
142 this reason your should disable autosave for encrypted files.