{"id":832,"date":"2018-10-06T16:19:33","date_gmt":"2018-10-06T13:19:33","guid":{"rendered":"http:\/\/kifarunix.com\/?p=832"},"modified":"2023-05-14T11:40:23","modified_gmt":"2023-05-14T08:40:23","slug":"how-to-encrypt-files-and-folders-with-ecryptfs-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-encrypt-files-and-folders-with-ecryptfs-on-ubuntu-18-04\/","title":{"rendered":"How to Encrypt Files and Folders with eCryptFS on Ubuntu 18.04"},"content":{"rendered":"\n<div><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/encrypt-files-and-folders-using-ecryptfs.png\" class=\"td-modal-image\"><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1063\" height=\"591\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/encrypt-files-and-folders-using-ecryptfs.png\" alt=\"Encrypt Files and Folders with eCryptFS on Ubuntu\" class=\"wp-image-16623\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/encrypt-files-and-folders-using-ecryptfs.png?v=1684053552 1063w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/encrypt-files-and-folders-using-ecryptfs-768x427.png?v=1684053552 768w\" sizes=\"(max-width: 1063px) 100vw, 1063px\" \/><\/figure><\/a><\/div>\n\n\n\n<p>In this tutorial, you will learn how to Encrypt Files and Folders with <a href=\"https:\/\/www.ecryptfs.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">eCryptFS<\/a> on Ubuntu 18.04. <strong>Encryption<\/strong> is the process in which a plain text data, a message or information, is converted to a random and meaningless data, commonly known as ciphertext. Encrypted data can only accessed by authorized parties while those who are not authorized cannot access it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Encrypt Files and Folders with eCryptFS on Ubuntu<\/h2>\n\n\n\n<p>There are several methods of encrypting data in Linux for example EncFS, eCryptFS for filesystem level encryption, Loop-AES, DMCrypt, CipherShield for full disk encryption. Well, in this tutorial, we are going to learn how to encrypt files and folders on Ubuntu 18.04 by using eCryptFS utility.<\/p>\n\n\n\n<p><span class=\"em emphasis\">eCryptfs<\/span> is a POSIX-compliant enterprise-class stacked cryptographic filesystem for Linux. Layering on top of the filesystem layer <span class=\"em emphasis\">eCryptfs<\/span> protects files no matter the underlying filesystem, partition type, etc<\/p>\n\n\n\n<p>During installation, Ubuntu provides an option to encrypt the <span class=\"file filename\">\/home<\/span> partition using <span class=\"em emphasis\">eCryptfs<\/span>. This will automatically configure everything needed to encrypt and mount the partition However, if you dont get on pretty well with this, run through the following steps to ecnrypt your files and directories manually.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install eCryptFS on Ubuntu<\/h3>\n\n\n\n<p>To use eCryptFS, install the necessary packages. However, if you enabled home directory encryption during installation, this utility should already be installed.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><span class=\"cmd command\">sudo apt install ecryptfs-utils -y<\/span><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Encrypt a Directory using eCryptFS on Linux<\/h3>\n\n\n\n<p>Now that the installation is done, it is time to see ecryptfs in action. Let say\u00a0 you want to encrypt<strong> \/home\/$USER\/mydocuments<\/strong>.<\/p>\n\n\n\n<p>To encrypt the directory above, mount it with ecryptfs filesystem type as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo mount -t ecryptfs mydocuments\/ mydocuments\/<\/code><\/pre>\n\n\n\n<p>When this command is run, it asks for a passphrase and several other prompts. Answer them accordingly.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\nPassphrase:&nbsp;&nbsp;&nbsp;&nbsp;<strong>Enter your passpharase here<\/strong>\nSelect cipher:\n1) aes: blocksize = 16; min keysize = 16; max keysize = 32\n2) blowfish: blocksize = 8; min keysize = 16; max keysize = 56\n3) des3_ede: blocksize = 8; min keysize = 24; max keysize = 24\n4) twofish: blocksize = 16; min keysize = 16; max keysize = 32\n5) cast6: blocksize = 16; min keysize = 16; max keysize = 32\n6) cast5: blocksize = 8; min keysize = 5; max keysize = 16\nSelection [aes]:&nbsp; <strong>Press Enter<\/strong>\nSelect key bytes: \n1) 16\n2) 32\n3) 24\nSelection [16]:&nbsp; <strong>Press Enter<\/strong>\nEnable plaintext passthrough (y\/n) [n]: <strong>n<\/strong>\nEnable filename encryption (y\/n) [n]:<strong> n<\/strong>\nAttempting to mount with the following options:\necryptfs_unlink_sigs\necryptfs_key_bytes=16\necryptfs_cipher=aes\necryptfs_sig=96b6fac91e0a01b8\nMounted eCryptfs\n<\/code><\/pre>\n\n\n\n<p>The encrypted directory is now mounted. Run the command below to verify the mounting.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo mount | grep mydocuments<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/home\/$USER\/mydocuments on \/home\/$USER\/mydocuments type ecryptfs (rw,relatime,ecryptfs_sig=96b6fac91e0a01b8,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_unlink_sigs)<\/code><\/pre>\n\n\n\n<p>You can now start putting your sensitive data to the directory. As an example, let us create a file with random data within the encrypted directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cat mydocuments\/clients-contacts.txt<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ClientA: 020-000001\nClientB: 020-000002\nClientC: 020-000003\nClientD: 020-000004<\/code><\/pre>\n\n\n\n<p>As long as the directory is mounted, the data is accessible. Let us unmount the directory and see if it is possible to access the data.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo umount \/home\/$USER\/mydocuments<\/code><\/pre>\n\n\n\n<p>Try to view the data now.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cat mydocuments\/clients-contacts.txt<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nP.p\"3DUfw`\u0584[PJP5~p_CONSOLE9mx\u01eeP|Xt\u07eb0ak!f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a29Cj#@k\u043e-=wK ;jt\ue30fIPlP}I&amp;9 *]nL2XYG||V fyha4SC:Ox&lt;AJ2\u0763',fy:[p0u2t+ ?\ue8b6\u0535\u02ab\u0305x~Z%\u069422#&amp;7*Yxdg\n#t-7dZZUnGJ\/6[,e_m\ua879]N=~c\u024f|tQ0c4Q.,-AZaJ\/n%-zPm\u7d73v`#+{[n%l}U\\9=_'(Sdq&amp;b&amp;44C5,\nU9\u07efYK\u02df{O_xja423-@X4x~t\u0167K0\u8369t]?qwN!dM\u051eWl]SD;4&gt;yr|a.\n\u0590665G|-ulJw$2&lt;F1nn\"\u0460X7PF&lt;,q*~aW%'C&amp;I2'\u057d\nS{~~H@q.yQd;,?o \u00efqx+5q69{i]ax1;7@&gt;HOX:=M|zb&lt;I\u51e2K3QFz\"?02C}mdj\/|8xP\u072b\u07dc9b3~Q2\u031ch\n<\/code><\/pre>\n\n\n\n<p>This is all meaningless. To access the data, you need to remount the directory. When prompted for the passphrase, use the one you set while mounting the directory for the first time.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo mount -t ecryptfs mydocuments\/ mydocuments\/<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nPassphrase:&nbsp;&nbsp;&nbsp;&nbsp;<strong>Enter your Previous passpharase here<\/strong>\nSelect cipher:\n1) aes: blocksize = 16; min keysize = 16; max keysize = 32\n2) blowfish: blocksize = 8; min keysize = 16; max keysize = 56\n3) des3_ede: blocksize = 8; min keysize = 24; max keysize = 24\n4) twofish: blocksize = 16; min keysize = 16; max keysize = 32\n5) cast6: blocksize = 16; min keysize = 16; max keysize = 32\n6) cast5: blocksize = 8; min keysize = 5; max keysize = 16\nSelection [aes]:&nbsp; <strong>Press Enter<\/strong>\nSelect key bytes: \n1) 16\n2) 32\n3) 24\nSelection [16]:&nbsp; <strong>Press Enter<\/strong>\nEnable plaintext passthrough (y\/n) [n]: <strong>n<\/strong>\nEnable filename encryption (y\/n) [n]:<strong> n<\/strong>\nAttempting to mount with the following options:\necryptfs_unlink_sigs\necryptfs_key_bytes=16\necryptfs_cipher=aes\necryptfs_sig=96b6fac91e0a01b8\nMounted eCryptfs\n<\/code><\/pre>\n\n\n\n<p>You can now be able to view your data in the encrypted directory.<\/p>\n\n\n\n<p>The process of remounting the directory is so manual and a bit taunting. Therefore, to automate this process, you can create a bash script or use a USB with a passphrase key to automate this process.<\/p>\n\n\n\n<p>See our next tutorial on <a href=\"https:\/\/kifarunix.com\/security\/how-to-automate-ecryptfs-mounting-procedure\/\" target=\"_blank\" rel=\"noopener\">how to automate this mounting process<\/a>. Cheers.<\/p>\n\n\n\n<p>That marks the end of our tutorial on how to encrypt files and folders with eCryptFS on Ubuntu 18.04.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-use-veracrypt-on-command-line-to-encrypt-drives-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Use VeraCrypt on Command Line to Encrypt Drives on Ubuntu 18.04<\/a><\/p>\n\n\n\n<p><a class=\"rank-math-link\" href=\"https:\/\/kifarunix.com\/install-and-setup-veracrypt-on-ubuntu-20-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Setup VeraCrypt on Ubuntu 20.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/encrypt-drives-with-luks-in-linux\/\" target=\"_blank\" rel=\"noopener\" aria-current=\"page\" data-schema-attribute=\"\">Encrypt Drives with LUKS in Linux<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/automount-luks-encrypted-device-in-linux\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Automount LUKS Encrypted Device in Linux<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to Encrypt Files and Folders with eCryptFS on Ubuntu 18.04. Encryption is the process in which a plain<\/p>\n","protected":false},"author":1,"featured_media":8532,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[34,159],"tags":[161,160,3386,3387,3388,67],"class_list":["post-832","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security","category-encryption","tag-ecryptfs","tag-encryption","tag-how-to-encrypt-directories-with-ecryptfs","tag-how-to-encrypt-files-with-ecryptfs","tag-how-to-use-ecryptfs-on-linux","tag-ubuntu-18-04","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/832"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=832"}],"version-history":[{"count":7,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/832\/revisions"}],"predecessor-version":[{"id":16624,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/832\/revisions\/16624"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/8532"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}