{"id":6351,"date":"2018-05-01T14:07:42","date_gmt":"2018-05-01T18:07:42","guid":{"rendered":"https:\/\/www.thesslstore.com\/blog\/?p=6351"},"modified":"2021-06-10T15:50:09","modified_gmt":"2021-06-10T19:50:09","slug":"openssl-commands-cheat-sheet","status":"publish","type":"post","link":"https:\/\/www.thesslstore.com\/blog\/openssl-commands-cheat-sheet\/","title":{"rendered":"OpenSSL Commands Cheat Sheet: The Most Useful Commands"},"content":{"rendered":"<h2>Here\u2019s a list of the most useful OpenSSL commands<\/h2>\n<p>When it comes to SSL\/TLS certificates and their implementation, there is no tool as useful as OpenSSL. Being an open-source tool, OpenSSL is available for Windows, Linux, macOS, Solaris, QNX and most of major operating systems.<\/p>\n<p>With its core library written in C programming language, OpenSSL commands can be used to perform hundreds of functions ranging from the CSR generation to converting certificate formats. But for someone who just wants to install an SSL certificate, only a handful of commands are really necessary.<\/p>\n<p>That\u2019s why we\u2019ve come up with the most commonly used OpenSSL commands along with their applications. Have a look:<span id=\"newline\"><\/span><\/p>\n<h2>OpenSSL Command to Generate Private Key<\/h2>\n<pre>openssl genrsa -out yourdomain.key 2048<\/pre>\n<h2>OpenSSL Command to Check your Private Key<\/h2>\n<pre>openssl rsa -in privateKey.key -check<\/pre>\n<h2>OpenSSL Command to Generate CSR<\/h2>\n<p><strong>If you have generated Private Key:<\/strong><\/p>\n<pre>openssl req -new -key yourdomain.key -out yourdomain.csr<\/pre>\n<p>Once you execute this command, you\u2019ll be asked additional details. Enter them as below:<\/p>\n<ul>\n<li><strong>Country Name:<\/strong> 2-digit country code where your organization is legally located.<\/li>\n<li><strong>State\/Province:<\/strong> Write the full name of the state where your organization is legally located.<\/li>\n<li><strong>City:<\/strong> Write the full name of the city where your organization is legally located.<\/li>\n<li><strong>Organization Name:<\/strong> Write the legal name of your organization.<\/li>\n<li><strong>Organization Unit:<\/strong> Name of the department (Not Compulsory. Press Enter to skip)<\/li>\n<li><strong>Common Name:<\/strong> Your Fully Qualified Domain Name (e.g., www.yourdomainname.com.)<\/li>\n<li><strong>Email:<\/strong> The email ID through which certification will take place (Not Compulsory. Press Enter to skip)<\/li>\n<\/ul>\n<p><strong>If you haven\u2019t generated your Private Key yet:<\/strong><\/p>\n<p>This command will generate CSR and private key in a single shot.<\/p>\n<pre>openssl req -new \\\n\n-newkey rsa:2048 -nodes -keyout yourdomain.key \\\n\n-out yourdomain.csr \\\n\n-subj \"\/C=US\/ST=Florida\/L=Saint Petersburg\/O=Your Company, Inc.\/OU=IT\/CN=yourdomain.com\"<\/pre>\n<ul>\n<li><strong>Country Name:<\/strong> 2-digit country code where your organization is legally located.<\/li>\n<li><strong>State\/Province:<\/strong> Write the full name of the state where your organization is legally located.<\/li>\n<li><strong>City:<\/strong> Write the full name of the city where your organization is legally located.<\/li>\n<li><strong>Organization Name:<\/strong> Write the legal name of your organization.<\/li>\n<li><strong>Organization Unit:<\/strong> Name of the department<\/li>\n<li><strong>Common Name:<\/strong> Your Fully Qualified Domain Name<\/li>\n<\/ul>\n<span style=\"display:none\" class=\"tl-placeholder-f-type-shortcode_12753\"><\/span>\n<h2>OpenSSL Command to Check CSR<\/h2>\n<pre>openssl req -text -noout -verify -in CSR.csr<\/pre>\n<h2>OpenSSL Commands to Convert Certificate and Key Files<\/h2>\n<p>OpenSSL commands to convert PEM file:<\/p>\n<p><strong>Convert PEM to DER<\/strong><\/p>\n<pre>openssl x509 -outform der -in certificate.pem -out certificate.der<\/pre>\n<p><strong>Convert PEM to P7B<\/strong><\/p>\n<pre>openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cert<\/pre>\n<p><strong>Convert PEM to PFX<\/strong><\/p>\n<pre>openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt<\/pre>\n<p>OpenSSL commands to convert DER file<\/p>\n<p><strong>Convert DER to PEM<\/strong><\/p>\n<p>To convert certificate file:<\/p>\n<pre>openssl x509 -inform DER -in yourdomain.der -outform PEM -out yourdomain.crt<\/pre>\n<p>To convert private key file:<\/p>\n<pre>openssl rsa -inform DER -in yourdomain_key.der -outform PEM -out yourdomain.key<\/pre>\n<p>OpenSSL commands to convert P7B file<\/p>\n<p><strong>Convert P7B to PEM<\/strong><\/p>\n<pre>openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer<\/pre>\n<p><strong>Convert P7B to PFX<\/strong><\/p>\n<pre>openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer\n\nopenssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer<\/pre>\n<p>OpenSSL commands to convert PKCS#12 (.pfx) file<\/p>\n<p><strong>Convert PFX to PEM<\/strong><\/p>\n<p>To convert certificate file:<\/p>\n<pre>openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes<\/pre>\n<p>To convert private key file:<\/p>\n<pre>openssl pkcs12 -in yourdomain.pfx -nocerts -out yourdomain.key -nodes<\/pre>\n<h2>OpenSSL Command to Check a certificate<\/h2>\n<pre>openssl x509 -in certificate.crt -text -noout<\/pre>\n<h2>OpenSSL Command to Check a PKCS#12 file (.pfx file)<\/h2>\n<pre>openssl pkcs12 -info -in keyStore.p12<\/pre>\n<p>Did we miss out on any? Please let us know in the comment section below.<\/p>\n<span style=\"display:none\" class=\"tl-placeholder-f-type-shortcode_14540\"><\/span>\n","protected":false},"excerpt":{"rendered":"<p>Here\u2019s a list of the most useful OpenSSL commands When it comes to SSL\/TLS certificates and their implementation, there is no tool as useful as OpenSSL. Being an open-source tool,&#8230;<\/p>\n","protected":false},"author":10,"featured_media":6352,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":"","tve_updated_post":"","tve_custom_css":"","tve_user_custom_css":"","tve_globals":{},"tcb2_ready":0,"tcb_editor_enabled":0,"tve_landing_page":"","_tve_header":"","_tve_footer":""},"categories":[130],"tags":[7123],"class_list":["post-6351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-everything-encryption","tag-openssl","post-with-tags"],"views":85295,"jetpack_featured_media_url":"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/05\/bigstock-177983458.jpg","_links":{"self":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/posts\/6351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/comments?post=6351"}],"version-history":[{"count":0,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/posts\/6351\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/media\/6352"}],"wp:attachment":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/media?parent=6351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/categories?post=6351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/tags?post=6351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}