{"id":812,"date":"2012-07-11T17:22:29","date_gmt":"2012-07-11T14:22:29","guid":{"rendered":"http:\/\/joseph.zikusooka.com\/?p=812"},"modified":"2012-07-12T19:28:20","modified_gmt":"2012-07-12T16:28:20","slug":"how-to-create-an-encrypted-usb-drive-in-linux-using-the-command-line","status":"publish","type":"post","link":"https:\/\/joseph.zikusooka.com\/?p=812","title":{"rendered":"How to create an encrypted USB drive in Linux using the command line"},"content":{"rendered":"<p>Recently, I was tasked to write a backup program for a small office.  A key requirement was that the portable backup drive they are using needed to be encrypted since it would have to be ferried off site on a daily basis.  The idea was that, if the drive fell in the &#8216;wrong hands&#8217; during transportation, the client&#8217;s data would be secure.  With encryption, I was able to meet this need.<br \/>\nI thought I would break the silence with a how-to on encryption using the Linux command line interface \u2013 not exciting but quite necessary these days.<\/p>\n<p>Encrypting data in Linux is very simple, and I would highly recommend it for such things as USB flash and portable hard disks.  Most Linux distributions come with an encryption tool called cryptsetup.<br \/>\nIf you do not have it , install it using yum or apt-get depending on your package manager.  For Red hat based distros, use <\/p>\n<p><code># yum install cryptsetup<\/code><\/p>\n<p>As always, you need to backup your data before you proceed.  I will assume you have already created a new partition on your device e.g. \/dev\/sdX1.  If you need to partition, refer to the venerable &#8216;fdisk&#8217; utility<\/p>\n<p>Create the encrypted volume<\/p>\n<p><code># cryptsetup -v -y  luksFormat \/dev\/sdX1<\/code><br \/>\nConfirm that you want to proceed by typing \u201cYES\u201d<br \/>\nEnter your passphrase when prompted.  You will be asked to verify it<br \/>\nOnce you have created the encrypted volume, you can proceed to format it<\/p>\n<p><code># cryptsetup luksOpen \/dev\/sdX1 mydata<br \/>\n# mkfs.ext3 \/dev\/mapper\/mydata<\/code><br \/>\nHere you can choose other file formats such as FAT32, EXT4 etc<\/p>\n<p>Create a mount point<\/p>\n<p><code># mkdir  \/mnt\/mydata<\/code><\/p>\n<p>Mount the new volume<\/p>\n<p><code># mount \/dev\/mapper\/mydata \/mnt\/mydata<\/code><br \/>\nYou can then write your data to the mounted and encrypted volume at \/mnt\/mydata<\/p>\n<p>To close the volume<\/p>\n<p><code># umount \/dev\/mapper\/mydata<br \/>\n# cryptsetup luksClose mydata<\/code><\/p>\n<p>Note: if you are using a desktop such as GNOME, you will be prompted for a passphrase every time you insert the disk, so you do not have to mount the disk manually, but then again, we are talking about the command line here!<\/p>\n<p>That&#8217;s it for now<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I was tasked to write a backup program for a small office. A key requirement was that the portable backup drive they are using needed to be encrypted since it would have to be ferried off site on a daily basis. The idea was that, if the drive fell in the &#8216;wrong hands&#8217; during [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-812","post","type-post","status-publish","format-standard","hentry","category-tips"],"_links":{"self":[{"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/posts\/812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=812"}],"version-history":[{"count":9,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/posts\/812\/revisions"}],"predecessor-version":[{"id":815,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=\/wp\/v2\/posts\/812\/revisions\/815"}],"wp:attachment":[{"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joseph.zikusooka.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}