{"id":5677,"date":"2013-06-16T09:15:40","date_gmt":"2013-06-16T13:15:40","guid":{"rendered":"http:\/\/g33kinfo.com\/info\/?p=5677"},"modified":"2013-06-16T09:15:40","modified_gmt":"2013-06-16T13:15:40","slug":"10-ways-to-generate-a-random-password-from-the-command-line","status":"publish","type":"post","link":"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/","title":{"rendered":"10 Ways to Generate a Random Password from the Command Line"},"content":{"rendered":"<p>From <a href=\"http:\/\/www.howtogeek.com\/howto\/30184\/10-ways-to-generate-a-random-password-from-the-command-line\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.howtogeek.com<\/a><\/p>\n<p>One of the great things about Linux is that you can do the same thing hundreds of different ways\u2014even something as simple as generating a random password can be accomplished with dozens of different commands. Here\u2019s 10 ways you can do it.<\/p>\n<p>We gathered all of these commands from Command-Line Fu and tested them out on our own Linux PC to make sure they work. You should be able to use at least some of these on Windows with Cygwin installed, though we didn\u2019t test all of them\u2014the last one definitely works though.<br \/>\nGenerate a Random Password<\/p>\n<p>For any of these random password commands, you can either modify them to output a different password length, or you can just use the first x characters of the generated password if you don\u2019t want such a long password. Hopefully you\u2019re using a password manager like LastPass anyway so you don\u2019t need to memorize them.<br \/>\n<!--more--><br \/>\nThis method uses SHA to hash the date, runs through base64, and then outputs the top 32 characters.<\/p>\n<p>    <code>date +%s | sha256sum | base64 | head -c 32 ; echo<\/code><br \/>\n&nbsp;<\/p>\n<p>This method used the built-in \/dev\/urandom feature, and filters out only characters that you would normally use in a password. Then it outputs the top 32.<\/p>\n<p>    <code>< \/dev\/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;<\/code><br \/>\n&nbsp;<\/p>\n<p>This one uses openssl\u2019s rand function, which may not be installed on your system. Good thing there\u2019s lots of other examples, right?<\/p>\n<p>    <\/code><code>openssl rand -base64 32<\/code><br \/>\n&nbsp;<\/p>\n<p>This one works a lot like the other urandom one, but just does the work in reverse. Bash is very powerful!<\/p>\n<p>    <code>tr -cd '[:alnum:]' < \/dev\/urandom | fold -w30 | head -n1<\/code><br \/>\n&nbsp;<\/p>\n<p>Here\u2019s another example that filters using the strings command, which outputs printable strings from a file, which in this case is the urandom feature.<\/p>\n<p>    <\/code><code>strings \/dev\/urandom | grep -o ':alnum:' | head -n 30 | tr -d '\\n'; echo<\/code><br \/>\n&nbsp;<\/p>\n<p>Here\u2019s an even simpler version of the urandom one.<\/p>\n<p>   <code>< \/dev\/urandom tr -dc _A-Z-a-z-0-9 | head -c6<\/code><br \/>\n&nbsp;<\/p>\n<p>This one manages to use the very useful dd command.<\/p>\n<p>    <\/code><code>dd if=\/dev\/urandom bs=1 count=32 2>\/dev\/null | base64 -w 0 | rev | cut -b 2- | rev<\/code><br \/>\n&nbsp;<\/p>\n<p>You can even create a random left-hand password, which would let you type your password with one hand.<\/p>\n<p>    <code>< \/dev\/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c8; echo \"\" <\/code><br \/>\n&nbsp;<\/p>\n<p>If you\u2019re going to be using this all the time, it\u2019s probably a better idea to put it into a function. In this case, once you run the command once, you\u2019ll be able to use randpw anytime you want to generate a random password. You\u2019d probably want to put this into your ~\/.bashrc file.<\/p>\n<p>    <\/code><code>randpw(){ < \/dev\/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}<\/code><br \/>\nYou can use this same syntax to make any of these into a function\u2014just replace everything inside the { }<br \/>\n&nbsp;<\/p>\n<p>And here\u2019s the easiest way to make a password from the command line, which works in Linux, Windows with Cygwin, and probably Mac OS X. I\u2019m sure that some people will complain that it\u2019s not as random as some of the other options, but honestly, it\u2019s random enough if you\u2019re going to be using the whole thing.<\/p>\n<p>    <\/code><code>date | md5sum<\/code><br \/>\n&nbsp;<\/p>\n<p>Yeah, that\u2019s even easy enough to remember. There\u2019s loads of other ways that you can create a random password from the command line in Linux\u2014for instance, the mkpasswd command, which can actually assign the password to a Linux user account. <\/p>\n<p>Also, here&#8217;s a one liner:<\/p>\n<p><code>python -c 'import crypt; print crypt.crypt(\"test\", \"$6$random_salt\")'<\/code><\/p>\n<p>6 is the type of hash for SHA-512<\/p>\n<p>    1 -> MD5<br \/>\n    2a -> Blowfish (not in mainline glibc; added in some Linux distributions)<br \/>\n    5 -> SHA-256 (since glibc 2.7)<br \/>\n    6 -> SHA-512 (since glibc 2.7)<\/p>\n<p>I&#8217;d recommend you investigate what salts are to make sure you know the difference between encryption and hashing.<\/p>\n<p>Also<br \/>\n<code>mkpasswd -l 15 -d 3 -C 5 -s 5<br \/>\nalias cryptpw='read pass;echo $pass|md5sum|base64|cut -c -16'<\/code><br \/>\ncan be used in various ways as well..<\/p>\n<p>So what\u2019s your favorite way?<\/p>\n<p>From <a href=\"http:\/\/www.howtogeek.com\/howto\/30184\/10-ways-to-generate-a-random-password-from-the-command-line\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.howtogeek.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>From http:\/\/www.howtogeek.com One of the great things about Linux is that you can do the same thing hundreds of different ways\u2014even something as simple as generating a random password can be accomplished with dozens of different commands. Here\u2019s 10 ways you can do it. We gathered all of these commands from Command-Line Fu and tested&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-5677","post","type-post","status-publish","format-standard","hentry","category-info"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>10 Ways to Generate a Random Password from the Command Line - Linux Shtuff<\/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:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"10 Ways to Generate a Random Password from the Command Line - Linux Shtuff\" \/>\n<meta property=\"og:description\" content=\"From http:\/\/www.howtogeek.com One of the great things about Linux is that you can do the same thing hundreds of different ways\u2014even something as simple as generating a random password can be accomplished with dozens of different commands. Here\u2019s 10 ways you can do it. We gathered all of these commands from Command-Line Fu and tested... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Shtuff\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:author\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:published_time\" content=\"2013-06-16T13:15:40+00:00\" \/>\n<meta name=\"author\" content=\"g33kadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/drsinger1111\" \/>\n<meta name=\"twitter:site\" content=\"@drsinger1111\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/10-ways-to-generate-a-random-password-from-the-command-line\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/10-ways-to-generate-a-random-password-from-the-command-line\\\/\"},\"author\":{\"name\":\"g33kadmin\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"headline\":\"10 Ways to Generate a Random Password from the Command Line\",\"datePublished\":\"2013-06-16T13:15:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/10-ways-to-generate-a-random-password-from-the-command-line\\\/\"},\"wordCount\":590,\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"articleSection\":[\"General Info\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/10-ways-to-generate-a-random-password-from-the-command-line\\\/\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/10-ways-to-generate-a-random-password-from-the-command-line\\\/\",\"name\":\"10 Ways to Generate a Random Password from the Command Line - Linux Shtuff\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\"},\"datePublished\":\"2013-06-16T13:15:40+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/10-ways-to-generate-a-random-password-from-the-command-line\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/10-ways-to-generate-a-random-password-from-the-command-line\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/10-ways-to-generate-a-random-password-from-the-command-line\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"10 Ways to Generate a Random Password from the Command Line\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\",\"name\":\"Linux Shtuff\",\"description\":\"Because I have CRS Syndrome...\",\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\",\"name\":\"g33kadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"contentUrl\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"width\":512,\"height\":512,\"caption\":\"g33kadmin\"},\"logo\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\"},\"description\":\"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\\\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....\",\"sameAs\":[\"https:\\\/\\\/thelinuxreport.com\",\"https:\\\/\\\/fb.me\\\/g33kinf0\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/drsinger1111\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"10 Ways to Generate a Random Password from the Command Line - Linux Shtuff","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:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/","og_locale":"en_US","og_type":"article","og_title":"10 Ways to Generate a Random Password from the Command Line - Linux Shtuff","og_description":"From http:\/\/www.howtogeek.com One of the great things about Linux is that you can do the same thing hundreds of different ways\u2014even something as simple as generating a random password can be accomplished with dozens of different commands. Here\u2019s 10 ways you can do it. We gathered all of these commands from Command-Line Fu and tested... Read More","og_url":"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/","og_site_name":"Linux Shtuff","article_publisher":"https:\/\/fb.me\/g33kinf0","article_author":"https:\/\/fb.me\/g33kinf0","article_published_time":"2013-06-16T13:15:40+00:00","author":"g33kadmin","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/drsinger1111","twitter_site":"@drsinger1111","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/#article","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/"},"author":{"name":"g33kadmin","@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"headline":"10 Ways to Generate a Random Password from the Command Line","datePublished":"2013-06-16T13:15:40+00:00","mainEntityOfPage":{"@id":"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/"},"wordCount":590,"publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"articleSection":["General Info"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/","url":"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/","name":"10 Ways to Generate a Random Password from the Command Line - Linux Shtuff","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/#website"},"datePublished":"2013-06-16T13:15:40+00:00","breadcrumb":{"@id":"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/g33kinfo.com\/info\/10-ways-to-generate-a-random-password-from-the-command-line\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/g33kinfo.com\/info\/"},{"@type":"ListItem","position":2,"name":"10 Ways to Generate a Random Password from the Command Line"}]},{"@type":"WebSite","@id":"https:\/\/g33kinfo.com\/info\/#website","url":"https:\/\/g33kinfo.com\/info\/","name":"Linux Shtuff","description":"Because I have CRS Syndrome...","publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/g33kinfo.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547","name":"g33kadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","url":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","contentUrl":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","width":512,"height":512,"caption":"g33kadmin"},"logo":{"@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif"},"description":"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....","sameAs":["https:\/\/thelinuxreport.com","https:\/\/fb.me\/g33kinf0","https:\/\/x.com\/https:\/\/twitter.com\/drsinger1111"]}]}},"_links":{"self":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/5677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/comments?post=5677"}],"version-history":[{"count":0,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/5677\/revisions"}],"wp:attachment":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/media?parent=5677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/categories?post=5677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/tags?post=5677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}