{"id":222,"date":"2017-05-11T09:45:53","date_gmt":"2017-05-11T14:45:53","guid":{"rendered":"http:\/\/etapien.com\/guides\/?p=222"},"modified":"2020-08-24T14:22:20","modified_gmt":"2020-08-24T19:22:20","slug":"password-protect-vim-file-linux","status":"publish","type":"post","link":"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/","title":{"rendered":"How to Password Protect a Vim File in Linux"},"content":{"rendered":"<p>Vim is a popular, feature-rich and highly-extensible text editor for Linux, and one of its special features is support for encrypting text files using various crypto methods with a password.<\/p>\n<p>In this article, we will explain to you one of the simple Vim usage tricks; password protecting a file using Vim in Linux. We will show you how to secure a file at the time of its creation as well as after opening it for modification.<\/p>\n<p>&nbsp;<\/p>\n<p>To install the full version of Vim, simply run this command:<\/p>\n<pre>$ sudo apt install vim          #Debian\/Ubuntu systems\r\n$ sudo yum install vim          #RHEL\/CentOS systems \r\n$ sudo dnf install vim\t\t#Fedora 22+\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>How to Password Protect a Vim File in Linux<\/h3>\n<p><center><ins class=\"adsbygoogle\" data-ad-client=\"ca-pub-2601749019656699\" data-ad-slot=\"5590002574\" data-ad-format=\"auto\" data-adsbygoogle-status=\"done\"><ins id=\"aswift_4_expand\"><ins id=\"aswift_4_anchor\"><\/ins><\/ins><\/ins><\/center>Vim has a <code>-x<\/code> option which enables you to use encryption when creating files. Once you run the vim command\u00a0below, you\u2019ll be prompted for a crypt key:<\/p>\n<pre><strong>$ vim -x file.txt<\/strong>\r\nWarning: Using a weak encryption method; see :help 'cm'\r\nEnter encryption key: <strong>*******<\/strong>\r\nEnter same key again: <strong>*******<\/strong>\r\n<\/pre>\n<p>If the crypto key matches after entering it for the second time, you can proceed to modify the file.<\/p>\n<div id=\"attachment_25578\" class=\"wp-caption aligncenter\" style=\"width: 649px;\">\n<p>&nbsp;<\/p>\n<p class=\"wp-caption-text\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium\" src=\"https:\/\/etapien.com\/guides\/img\/Vim-File-Password-Protected-File.png\" width=\"820\" height=\"233\" \/><\/p>\n<p class=\"wp-caption-text\">Vim File Password Protected<\/p>\n<\/div>\n<p>Once your done, press <code>[Esc]<\/code> and <code>:wq<\/code> to save and close the file. The next time you want to open it for editing, you\u2019ll have to enter the crypto key like this:<\/p>\n<pre><strong>$ vim file.txt<\/strong>\r\nNeed encryption key for \"file.txt\"\r\nWarning: Using a weak encryption method; see :help 'cm'\r\nEnter encryption key: <strong>*******<\/strong>\r\n<\/pre>\n<p>In case you enter a wrong password (or no key), you\u2019ll see some junk characters.<\/p>\n<div id=\"attachment_25579\" class=\"wp-caption aligncenter\">\n<p>&nbsp;<\/p>\n<p class=\"wp-caption-text\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium\" src=\"https:\/\/etapien.com\/guides\/img\/Vim-Content-Encrypted.png\" width=\"850\" height=\"231\" \/><\/p>\n<p class=\"wp-caption-text\">Vim Content Encrypted<\/p>\n<\/div>\n<h4>Setting a Strong Encryption Method in Vim<\/h4>\n<p><strong>Note<\/strong>: There is a warning indicating that a weak encryption method has been used to protect the file. Next, we\u2019ll see how to set a strong encryption method in Vim.<\/p>\n<div id=\"attachment_25580\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/wwwtecmintcom-vcko128hufjif0.stackpathdns.com\/wp-content\/uploads\/2017\/05\/Weak-Encryption-on-Vim-File.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-25580\" src=\"https:\/\/wwwtecmintcom-vcko128hufjif0.stackpathdns.com\/wp-content\/uploads\/2017\/05\/Weak-Encryption-on-Vim-File.png\" alt=\"Weak Encryption on Vim File\" width=\"649\" height=\"97\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Weak Encryption on Vim File<\/p>\n<\/div>\n<p>To check the set of cryptmethod(cm), type (scroll down to view all available methods):<\/p>\n<pre>:help 'cm'\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>                                                *'cryptmethod'* *'cm'*\r\n'cryptmethod' 'cm'      string  (default \"zip\")\r\nglobal or local to buffer |global-local|\r\n{not in Vi}\r\nMethod used for encryption when the buffer is written to a file:\r\n*pkzip*\r\nzip          PkZip compatible method.  A weak kind of encryption.\r\nBackwards compatible with Vim 7.2 and older.\r\n*blowfish*\r\nblowfish     Blowfish method.  Medium strong encryption but it has\r\nan implementation flaw.  Requires Vim 7.3 or later,\r\nfiles can NOT be read by Vim 7.2 and older.  This adds\r\na \"seed\" to the file, every time you write the file\r\noptions.txt [Help][RO]                                                                  \r\n<\/pre>\n<p>You can set a new cryptomethod on a Vim file as shown below (we\u2019ll use <strong>blowfish2<\/strong> in this example):<\/p>\n<pre>:setlocal cm=blowfish2\r\n<\/pre>\n<p>Then press <code>[Enter]<\/code> and <code>:wq<\/code> to save the file.<\/p>\n<div id=\"attachment_25581\" class=\"wp-caption aligncenter\">\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium\" src=\"https:\/\/etapien.com\/guides\/img\/Set-Strong-Encryption-on-Vim-File.png\" width=\"850\" height=\"230\" \/><\/p>\n<p class=\"wp-caption-text\">Set Strong Encryption on Vim File<\/p>\n<\/div>\n<p>Now you should not see the warning message when you open the file again as shown below.<\/p>\n<pre><strong>$ vim file.txt<\/strong>\r\nNeed encryption key for \"file.txt\"\r\nEnter encryption key: <strong>*******<\/strong>\r\n<\/pre>\n<p>You can also set a password after opening a Vim text file, use the command<code>:X<\/code> and set a crypto pass like shown above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vim is a popular, feature-rich and highly-extensible text editor for Linux, and one of its special features is support for encrypting text files using various crypto methods with a password. In this article, we will explain to you one of the simple Vim usage tricks; password protecting a file using Vim in Linux. We will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Password Protect a Vim File in Linux - Tech Howtos<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Password Protect a Vim File in Linux - Tech Howtos\" \/>\n<meta property=\"og:description\" content=\"Vim is a popular, feature-rich and highly-extensible text editor for Linux, and one of its special features is support for encrypting text files using various crypto methods with a password. In this article, we will explain to you one of the simple Vim usage tricks; password protecting a file using Vim in Linux. We will [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"Tech Howtos\" \/>\n<meta property=\"article:published_time\" content=\"2017-05-11T14:45:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-24T19:22:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/etapien.com\/guides\/img\/Vim-File-Password-Protected-File.png\" \/>\n<meta name=\"author\" content=\"Etapien\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Etapien\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/\",\"url\":\"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/\",\"name\":\"How to Password Protect a Vim File in Linux - Tech Howtos\",\"isPartOf\":{\"@id\":\"https:\/\/etapien.com\/guides\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/etapien.com\/guides\/img\/Vim-File-Password-Protected-File.png\",\"datePublished\":\"2017-05-11T14:45:53+00:00\",\"dateModified\":\"2020-08-24T19:22:20+00:00\",\"author\":{\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424\"},\"breadcrumb\":{\"@id\":\"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/#primaryimage\",\"url\":\"https:\/\/etapien.com\/guides\/img\/Vim-File-Password-Protected-File.png\",\"contentUrl\":\"https:\/\/etapien.com\/guides\/img\/Vim-File-Password-Protected-File.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/etapien.com\/guides\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Password Protect a Vim File in Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/etapien.com\/guides\/#website\",\"url\":\"https:\/\/etapien.com\/guides\/\",\"name\":\"Tech Howtos\",\"description\":\"Tech related useful howtos\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/etapien.com\/guides\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424\",\"name\":\"Etapien\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g\",\"caption\":\"Etapien\"},\"url\":\"https:\/\/etapien.com\/guides\/author\/Etapien\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Password Protect a Vim File in Linux - Tech Howtos","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/","og_locale":"en_US","og_type":"article","og_title":"How to Password Protect a Vim File in Linux - Tech Howtos","og_description":"Vim is a popular, feature-rich and highly-extensible text editor for Linux, and one of its special features is support for encrypting text files using various crypto methods with a password. In this article, we will explain to you one of the simple Vim usage tricks; password protecting a file using Vim in Linux. We will [&hellip;]","og_url":"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/","og_site_name":"Tech Howtos","article_published_time":"2017-05-11T14:45:53+00:00","article_modified_time":"2020-08-24T19:22:20+00:00","og_image":[{"url":"https:\/\/etapien.com\/guides\/img\/Vim-File-Password-Protected-File.png"}],"author":"Etapien","twitter_misc":{"Written by":"Etapien","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/","url":"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/","name":"How to Password Protect a Vim File in Linux - Tech Howtos","isPartOf":{"@id":"https:\/\/etapien.com\/guides\/#website"},"primaryImageOfPage":{"@id":"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/#primaryimage"},"image":{"@id":"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/etapien.com\/guides\/img\/Vim-File-Password-Protected-File.png","datePublished":"2017-05-11T14:45:53+00:00","dateModified":"2020-08-24T19:22:20+00:00","author":{"@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424"},"breadcrumb":{"@id":"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/#primaryimage","url":"https:\/\/etapien.com\/guides\/img\/Vim-File-Password-Protected-File.png","contentUrl":"https:\/\/etapien.com\/guides\/img\/Vim-File-Password-Protected-File.png"},{"@type":"BreadcrumbList","@id":"https:\/\/etapien.com\/guides\/password-protect-vim-file-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/etapien.com\/guides\/"},{"@type":"ListItem","position":2,"name":"How to Password Protect a Vim File in Linux"}]},{"@type":"WebSite","@id":"https:\/\/etapien.com\/guides\/#website","url":"https:\/\/etapien.com\/guides\/","name":"Tech Howtos","description":"Tech related useful howtos","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/etapien.com\/guides\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424","name":"Etapien","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g","caption":"Etapien"},"url":"https:\/\/etapien.com\/guides\/author\/Etapien\/"}]}},"_links":{"self":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/222"}],"collection":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/comments?post=222"}],"version-history":[{"count":3,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/222\/revisions"}],"predecessor-version":[{"id":226,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/222\/revisions\/226"}],"wp:attachment":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/media?parent=222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/categories?post=222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/tags?post=222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}