{"id":12550,"date":"2019-03-28T00:15:54","date_gmt":"2019-03-28T00:15:54","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12550"},"modified":"2019-03-28T00:21:38","modified_gmt":"2019-03-28T00:21:38","slug":"how-to-generate-encrypt-decrypt-random-passwords-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/how-to-generate-encrypt-decrypt-random-passwords-in-linux\/","title":{"rendered":"How to Generate\/Encrypt\/Decrypt Random Passwords in Linux"},"content":{"rendered":"<p>We have taken initiative to produce Linux tips and tricks series. If you\u2019ve missed the last article of this series, you may like to visit the link below.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/5-linux-command-line-tricks\/\" target=\"_blank\" rel=\"noopener\">5 Interesting Command Line Tips and Tricks in Linux<\/a><\/li>\n<\/ol>\n<p>In this article, we will share some interesting Linux tips and tricks to generate random passwords and also how to encrypt and decrypt passwords with or without slat method.<\/p>\n<p>Security is one of the major concern of digital age. We put on password to computers, email, cloud, phone, documents and what not. We all know the basic to choose the password that is easy to remember and hard to guess. What about some sort of machine based password generation automatically? Believe me Linux is very good at this.<\/p>\n<p><strong>1.<\/strong>\u00a0Generate a random unique password of length equal to\u00a0<strong>10<\/strong>\u00a0characters using command \u2018<strong>pwgen<\/strong>\u2018. If you have not installed\u00a0<strong>pwgen<\/strong>\u00a0yet, use Apt or YUM to get.<\/p>\n<pre>$ pwgen 10 1<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Generate-Random-Unique-Password-in-Linux.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12220\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Generate-Random-Unique-Password-in-Linux.gif\" alt=\"Generate Random Unique Password in Linux\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Generate several random unique passwords of character length 50 in one go!<\/p>\n<pre>$ pwgen 50\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Generate-Multiple-Random-Passwords.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12221\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Generate-Multiple-Random-Passwords.gif\" alt=\"Generate Multiple Random Passwords\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p><strong>2.<\/strong>\u00a0You may use \u2018<strong>makepasswd<\/strong>\u2018 to generate random, unique password of given length as per choice. Before you can fire\u00a0<strong>makepasswd<\/strong>\u00a0command, make sure you have installed it. If not! Try installing the package \u2018makepasswd\u2019 using Apt or YUM.<\/p>\n<p>Generate a random password of character length 10. Default Value is 10.<\/p>\n<pre>$ makepasswd \r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/mkpasswd-generate-unique-password.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12222\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/mkpasswd-generate-unique-password.gif\" alt=\"makepasswd Generate Unique Password\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Generate a random password of character length 50.<\/p>\n<pre>$ makepasswd  --char 50\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Random-Password-Generate.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12223\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Random-Password-Generate.gif\" alt=\"Random Password Generate\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Generate 7 random password of 20 characters.<\/p>\n<pre>$ makepasswd --char 20 --count 7\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Generate-20-Character-Password.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12224\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Generate-20-Character-Password.gif\" alt=\"Generate 20 Character Password\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p><strong>3.<\/strong>\u00a0Encrypt a password using crypt along with salt. Provide salt manually as well as automatically.<\/p>\n<p>For those who may not be aware of\u00a0<strong>salt<\/strong>,<\/p>\n<p><strong>Salt<\/strong>\u00a0is a random data which servers as an additional input to one way function in order to protect password against dictionary attack.<\/p>\n<p>Make sure you have installed\u00a0<strong>mkpasswd<\/strong>\u00a0installed before proceeding.<\/p>\n<p>The below command will encrypt the password with salt. The salt value is taken randomly and automatically. Hence every time you run the below command it will generate different output because it is accepting random value for salt every-time.<\/p>\n<pre>$ mkpasswd tecmint\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-Password-in-Linux.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12225\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-Password-in-Linux.gif\" alt=\"Encrypt Password in Linux Using mkpasswd\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Now lets define the salt. It will output the same result every-time. Note you can input anything of your choice as salt.<\/p>\n<pre>$ mkpasswd tecmint -s tt\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-Password-Using-Salt.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12226\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-Password-Using-Salt.gif\" alt=\"Encrypt Password Using Salt\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Moreover,\u00a0<strong>mkpasswd<\/strong>\u00a0is interactive and if you don\u2019t provide password along with the command, it will ask password interactively.<\/p>\n<p><strong>4.<\/strong>\u00a0Encrypt a string say \u201c<strong>Tecmint-is-a-Linux-Community<\/strong>\u201d using\u00a0<strong>aes-256-cbc<\/strong>\u00a0encryption using password say \u201c<strong>tecmint<\/strong>\u201d and salt.<\/p>\n<pre># echo Tecmint-is-a-Linux-Community | openssl enc -aes-256-cbc -a -salt -pass pass:tecmint\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-A-String-in-Linux.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12227\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Encrypt-A-String-in-Linux.gif\" alt=\"Encrypt A String in Linux\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Here in the above example the output of\u00a0<a href=\"https:\/\/www.tecmint.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">echo command<\/a>\u00a0is pipelined with\u00a0<strong>openssl<\/strong>\u00a0command that pass the input to be encrypted using Encoding with Cipher (enc) that uses\u00a0<strong>aes-256-cbc<\/strong>\u00a0encryption algorithm and finally with salt it is encrypted using password (<strong>tecmint<\/strong>).<\/p>\n<p><strong>5.<\/strong>\u00a0Decrypt the above string using openssl command using the\u00a0<strong>-aes-256-cbc<\/strong>\u00a0decryption.<\/p>\n<pre># echo U2FsdGVkX18Zgoc+dfAdpIK58JbcEYFdJBPMINU91DKPeVVrU2k9oXWsgpvpdO\/Z | openssl enc -aes-256-cbc -a -d -salt -pass pass:tecmint\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decrypt-String-in-Linux.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12228\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/03\/Decrypt-String-in-Linux.gif\" alt=\"Decrypt String in Linux\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>That\u2019s all for now. If you know any such tips and tricks you may send us your tips at\u00a0admin@tecmint.com, your tip will be published under your name and also we will include it in our future article.<\/p>\n<p>Keep connected. Keep Connecting. Stay Tuned.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/generate-encrypt-decrypt-random-passwords-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have taken initiative to produce Linux tips and tricks series. If you\u2019ve missed the last article of this series, you may like to visit the link below. 5 Interesting Command Line Tips and Tricks in Linux In this article, we will share some interesting Linux tips and tricks to generate random passwords and also &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/how-to-generate-encrypt-decrypt-random-passwords-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Generate\/Encrypt\/Decrypt Random Passwords in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12550","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12550"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12550\/revisions"}],"predecessor-version":[{"id":12554,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12550\/revisions\/12554"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}