<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pablo Endres&#039; Blog &#187; password</title>
	<atom:link href="http://www.pabloendres.com/tag/password/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pabloendres.com</link>
	<description></description>
	<lastBuildDate>Sun, 22 Jan 2012 19:20:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating passwords with bash + perl</title>
		<link>http://www.pabloendres.com/2009/09/22/creating-passwords-with-bash-perl/</link>
		<comments>http://www.pabloendres.com/2009/09/22/creating-passwords-with-bash-perl/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 20:44:53 +0000</pubDate>
		<dc:creator>Pablo Endres</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[create password]]></category>
		<category><![CDATA[mkpasswd]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.pabloendres.com/?p=107</guid>
		<description><![CDATA[I had a couple of scripts working in the back end of an application to create users and set the passwords. So instead of reinventing the wheel I used the ?trusty? useradd. Until recently one could pass the users password in clear text as a parameter. I assume that someone thought about all the passwords [...]]]></description>
			<content:encoded><![CDATA[<p>I had a couple of scripts working in the back end of an application to create users and set the passwords.  So instead of reinventing the wheel I used the ?<em>trusty</em>? useradd.</p>
<p>Until recently one could pass the users password in clear text as a parameter.  I assume that someone thought about all the passwords that word saved in history files and decided to change it.  The problem is that the used the same parameter but now it expected the password to be encrypted, so it basically stopped working but didn&#8217;t generate errors.</p>
<p>After some debugging and some man reading the problem was nailed down, but now I had to generate and encrypt the password.  I looked and tried many solutions but the best I could find was the crypt library and decided to access is through perl.  What I liked the most about the solution is that I could use all the same native algorithms that the system has installed.</p>
<p>So lets cut the chase, here are the 5 lines of code needed to get the job done:</p>
<blockquote><p>salt=$(/usr/bin/mkpasswd -l 8 -s 0)<br />
parameter=&#8221;print crypt(config,\&#8221;\\\$1\\\$$salt\&#8221;)&#8221;<br />
encrypted=$(perl -e &#8220;$parameter&#8221;)<br />
/usr/sbin/useradd -p $encrypted &lt;user&gt;</p></blockquote>
<p>To create a good salt I used the <em><strong>mkpasswd</strong></em> utility that comes with the expect package (yum install expect).  In this case the $1 is not a variable, but the way of telling crypt to use MD5.</p>
<p>Other valid values for the Glibc crypt are:</p>
<table border="1">
<tbody>
<tr>
<th>ID</th>
<th>Method</th>
</tr>
<tr>
<td>1</td>
<td>MD5</td>
</tr>
<tr>
<td>2a</td>
<td>Blowfish (not in mainline glibc; added in some Linux distributions)</td>
</tr>
<tr>
<td>5</td>
<td>SHA-256 (since glibc 2.7)</td>
</tr>
<tr>
<td>6</td>
<td>SHA-512 (since glibc 2.7)</td>
</tr>
</tbody>
</table>
<p>For more information http://www.kernel.org/doc/man-pages/online/pages/man3/crypt.3.html or simply: man crypt</p>
<p>Have fun</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pabloendres.com/2009/09/22/creating-passwords-with-bash-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

