Linux Upgrade Password Hashing Algorithm to SHA-512

by Vivek Gite · 9 comments

The default algorithm for storing password hashes in /etc/shadow is MD5. I was told to use SHA-512 hashing algorithm. How do I set password hashing using the SHA-256 and SHA-512 under CentOS or Redhat Enterprise Linux 5.4?

You need to use authconfig command to setup SHA-256/512 hashing. This command provides a simple method of configuring /etc/sysconfig/network to handle NIS, as well as /etc/passwd and /etc/shadow, the files used for shadow password support. Basic LDAP, Kerberos 5, and SMB (authentication) client configuration is also provided.

Display Current Hashing Algorithm

Type the following command:
# authconfig --test | grep hashing
Sample outputs:

password hashing algorithm is md5

Configure Linux Server To Use The SHA-512

To configure the Linux system to use the SHA-512 algorithm, enter:
# authconfig --passalgo=sha512 --update
Note users need to change their passwords in order to generate hashes using SHA-512. You can force users to change their password on next login:
# chage -d 0 userName

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 9 comments… read them below or add one }

1 Andrii 11.11.09 at 12:52 pm

Is it works in Debian?

2 iCroc 11.11.09 at 2:29 pm

This message appear

authconfig: Unknown password hashing algorithm specified, using sha256.

3 iCroc 11.11.09 at 10:19 pm

I have solved this problem by replacing this command
authconfig –passalgo=SHA512 –update
to
authconfig –passalgo=sha512 –update

Because no algorithm called SHA512

Best Regards

4 Philippe Petrinko 11.12.09 at 10:56 am

Hi Vivek,
This is an Interesting post. Thanks for writing it.

BTW, would you modify
# authconfig –passalgo=SHA512 –update

to lowercase “sha512″ as iCroc observed ?

5 kubrick 11.12.09 at 11:16 am

I’ve found this little article for Debian based systems.
You could change the default MD5 algorithm for the more secure Blowfish.

On Debian GNU/Linux, switching from the default MD5 algorithm to Blowfish is slightly more work, but still not terribly difficult to accomplish:

First, install the libpam-unix2 module. That can be done simply via APT, Debian’s software management system, using the command
# apt-get install libpam-unix2
Next, edit /etc/pam.d/common-auth, /etc/pam.d/common-account, /etc/pam.d/common-session, and /etc/pam.d/common-password so that in each file you replace pam_unix.so with pam_unix2.so.
Finally, while you are editing the common-password file, change the term md5 so that it reads blowfish instead.

Cheers!

6 Vivek Gite 11.12.09 at 1:17 pm

@ iCroc / Philippe

Thanks for pointing out the typo.

@ kubrick,

Thanks for sharing Debian specific information.

7 j0rn 11.24.09 at 11:45 pm

nice tip, thx :)
the algorithm corresponds to the second parameter in shadow passwords entries

user:$1$abcdef…

$1$ is md5 while $6$ is sha512, $0$ should be old des and $2$ blowfish I think

man crypt ;)

I updated my local users digest “by hand” by modifying the “ENCRYPT_METHOD” directive directly in login.defs, but I didn’t that -more elegant- way to do

8 KING SABRI 01.11.10 at 1:38 am

Thnaks Vivek

Fedora 12 by Default uses SHA-512
CentOS-5.4 by Default uses MD5
Ubuntu by Default uses MD5, But the command Not Found

9 Vivek Gite 01.11.10 at 4:46 am

Try kubrick comment # 5, it may work on Ubuntu too…

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All