{"id":323,"date":"2009-10-04T07:59:21","date_gmt":"2009-10-04T07:59:21","guid":{"rendered":"https:\/\/fir3netwp.gmsrrpobkbd.com\/2009\/10\/04\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux\/"},"modified":"2023-01-06T16:45:51","modified_gmt":"2023-01-06T16:45:51","slug":"password-protect-and-encryptsalt-a-file-with-openssl-in-linux","status":"publish","type":"post","link":"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html","title":{"rendered":"Linux: Password Protect & Encrypt File Using OpenSSL"},"content":{"rendered":"

In this article we will encrypt (using AES 256 cbc) and password protect (Salt the AES) a file using the openssl binary.<\/p>\n

The file we will encrypt will be the file secretfile.txt.As you can see it is just a plain text file.<\/p>\n

[root@linux tmp]# cat\u00a0 secretfile.txt
\nThis is a secret file that we do not want anyone to read.<\/p>\n

Encrypt File<\/strong><\/span><\/p>\n

Use the openssl comand to encrypt your file and then test the new file is fully encrypted.<\/p>\n

[root@linux tmp]# openssl aes-256-cbc -salt -in secretfile.txt -out secretfile.txt.aes
\nenter aes-256-cbc encryption password:
\nVerifying – enter aes-256-cbc encryption password:<\/p>\n

[root@linux tmp]# cat\u00a0 secretfile.txt.aes
\n3b\u00a6ted__\u00d9.:SL\u00ec\u00d5\u00a7\u00d5L<Jdc
\nu3A\u00c8F\\V!\u00ea:S2;\u00b3\u00e2\u00ff.Lfj\u00cf\u00a9\u00f9!_b*&)Stf\u00f9<\/p>\n

Decrypt File<\/span><\/strong><\/p>\n

Decrypt the file and then confirm the decypted file is readable.<\/p>\n

[root@linux tmp]# openssl aes-256-cbc -d -salt -in secretfile.txt.aes -out secretfile.txt
\nenter aes-256-cbc decryption password:<\/p>\n

[root@linux tmp]# cat secretfile.txt
\nThis is a secret file that we do not want anyone to read.<\/p>\n

Further notes : <\/em><\/strong>In a non-interactive scenario (such as using this within a script) were you require no input from the shell (user), you can use the -k to specify the password. Such as `openssl aes-256-cbc -salt -in secretfile.txt -out secretfile.txt.aes -k [password]`.<\/p>\n

\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"

In this article we will encrypt (using AES 256 cbc) and password protect (Salt the AES) a file using the openssl binary. The file we will encrypt will be the file secretfile.txt.As you can see it is just a plain text file. [root@linux tmp]# cat\u00a0 secretfile.txt This is a secret file that we do not … Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"yoast_head":"\nLinux: Password Protect & Encrypt File Using OpenSSL - Fir3net<\/title>\n<meta name=\"description\" content=\"In this article we will encrypt (using AES 256 cbc) and password protect (Salt the AES) a file using the openssl binary. The file we will encrypt will be\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux: Password Protect & Encrypt File Using OpenSSL - Fir3net\" \/>\n<meta property=\"og:description\" content=\"In this article we will encrypt (using AES 256 cbc) and password protect (Salt the AES) a file using the openssl binary. The file we will encrypt will be\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html\" \/>\n<meta property=\"og:site_name\" content=\"Fir3net\" \/>\n<meta property=\"article:published_time\" content=\"2009-10-04T07:59:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-06T16:45:51+00:00\" \/>\n<meta name=\"author\" content=\"Rick Donato\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rick Donato\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html\"},\"author\":{\"name\":\"Rick Donato\",\"@id\":\"https:\/\/www.fir3net.com\/#\/schema\/person\/ab35009601b7687ee1c5310be6038037\"},\"headline\":\"Linux: Password Protect & Encrypt File Using OpenSSL\",\"datePublished\":\"2009-10-04T07:59:21+00:00\",\"dateModified\":\"2023-01-06T16:45:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html\"},\"wordCount\":234,\"publisher\":{\"@id\":\"https:\/\/www.fir3net.com\/#organization\"},\"articleSection\":[\"Linux\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html\",\"url\":\"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html\",\"name\":\"Linux: Password Protect & Encrypt File Using OpenSSL - Fir3net\",\"isPartOf\":{\"@id\":\"https:\/\/www.fir3net.com\/#website\"},\"datePublished\":\"2009-10-04T07:59:21+00:00\",\"dateModified\":\"2023-01-06T16:45:51+00:00\",\"description\":\"In this article we will encrypt (using AES 256 cbc) and password protect (Salt the AES) a file using the openssl binary. The file we will encrypt will be\",\"breadcrumb\":{\"@id\":\"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.fir3net.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Operating Systems\",\"item\":\"https:\/\/www.fir3net.com\/os\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Linux\",\"item\":\"https:\/\/www.fir3net.com\/os\/linux\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Linux: Password Protect & Encrypt File Using OpenSSL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.fir3net.com\/#website\",\"url\":\"https:\/\/www.fir3net.com\/\",\"name\":\"Fir3net\",\"description\":\"Keeping you in the know\",\"publisher\":{\"@id\":\"https:\/\/www.fir3net.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.fir3net.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.fir3net.com\/#organization\",\"name\":\"Fir3net\",\"url\":\"https:\/\/www.fir3net.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.fir3net.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.fir3net.com\/wp-content\/uploads\/Fir3net-Background-Logo-compressed.png\",\"contentUrl\":\"https:\/\/www.fir3net.com\/wp-content\/uploads\/Fir3net-Background-Logo-compressed.png\",\"width\":390,\"height\":88,\"caption\":\"Fir3net\"},\"image\":{\"@id\":\"https:\/\/www.fir3net.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.fir3net.com\/#\/schema\/person\/ab35009601b7687ee1c5310be6038037\",\"name\":\"Rick Donato\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.fir3net.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d75d69a54c0ca3b32c24c3a9703b623c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d75d69a54c0ca3b32c24c3a9703b623c?s=96&d=mm&r=g\",\"caption\":\"Rick Donato\"},\"description\":\"Rick Donato is a Network Automation Architect\/Evangelist and the founder of Packet Coders.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linux: Password Protect & Encrypt File Using OpenSSL - Fir3net","description":"In this article we will encrypt (using AES 256 cbc) and password protect (Salt the AES) a file using the openssl binary. The file we will encrypt will be","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:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html","og_locale":"en_US","og_type":"article","og_title":"Linux: Password Protect & Encrypt File Using OpenSSL - Fir3net","og_description":"In this article we will encrypt (using AES 256 cbc) and password protect (Salt the AES) a file using the openssl binary. The file we will encrypt will be","og_url":"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html","og_site_name":"Fir3net","article_published_time":"2009-10-04T07:59:21+00:00","article_modified_time":"2023-01-06T16:45:51+00:00","author":"Rick Donato","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rick Donato","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html#article","isPartOf":{"@id":"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html"},"author":{"name":"Rick Donato","@id":"https:\/\/www.fir3net.com\/#\/schema\/person\/ab35009601b7687ee1c5310be6038037"},"headline":"Linux: Password Protect & Encrypt File Using OpenSSL","datePublished":"2009-10-04T07:59:21+00:00","dateModified":"2023-01-06T16:45:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html"},"wordCount":234,"publisher":{"@id":"https:\/\/www.fir3net.com\/#organization"},"articleSection":["Linux"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html","url":"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html","name":"Linux: Password Protect & Encrypt File Using OpenSSL - Fir3net","isPartOf":{"@id":"https:\/\/www.fir3net.com\/#website"},"datePublished":"2009-10-04T07:59:21+00:00","dateModified":"2023-01-06T16:45:51+00:00","description":"In this article we will encrypt (using AES 256 cbc) and password protect (Salt the AES) a file using the openssl binary. The file we will encrypt will be","breadcrumb":{"@id":"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.fir3net.com\/UNIX\/Linux\/password-protect-and-encryptsalt-a-file-with-openssl-in-linux.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.fir3net.com\/"},{"@type":"ListItem","position":2,"name":"Operating Systems","item":"https:\/\/www.fir3net.com\/os"},{"@type":"ListItem","position":3,"name":"Linux","item":"https:\/\/www.fir3net.com\/os\/linux"},{"@type":"ListItem","position":4,"name":"Linux: Password Protect & Encrypt File Using OpenSSL"}]},{"@type":"WebSite","@id":"https:\/\/www.fir3net.com\/#website","url":"https:\/\/www.fir3net.com\/","name":"Fir3net","description":"Keeping you in the know","publisher":{"@id":"https:\/\/www.fir3net.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.fir3net.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.fir3net.com\/#organization","name":"Fir3net","url":"https:\/\/www.fir3net.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.fir3net.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.fir3net.com\/wp-content\/uploads\/Fir3net-Background-Logo-compressed.png","contentUrl":"https:\/\/www.fir3net.com\/wp-content\/uploads\/Fir3net-Background-Logo-compressed.png","width":390,"height":88,"caption":"Fir3net"},"image":{"@id":"https:\/\/www.fir3net.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.fir3net.com\/#\/schema\/person\/ab35009601b7687ee1c5310be6038037","name":"Rick Donato","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.fir3net.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d75d69a54c0ca3b32c24c3a9703b623c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d75d69a54c0ca3b32c24c3a9703b623c?s=96&d=mm&r=g","caption":"Rick Donato"},"description":"Rick Donato is a Network Automation Architect\/Evangelist and the founder of Packet Coders."}]}},"_links":{"self":[{"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/posts\/323"}],"collection":[{"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/comments?post=323"}],"version-history":[{"count":2,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/posts\/323\/revisions"}],"predecessor-version":[{"id":3435,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/posts\/323\/revisions\/3435"}],"wp:attachment":[{"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/media?parent=323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/categories?post=323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/tags?post=323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}