@judepereira

Java/C/Objective C/Arduino/*nix. Everything awesome.

Use Ruby to Generate your Shadow Password

I was initially stumbled on creating the shadow compatible SHA-512 hash.
After a little research, the answer was obvious:

require 'digest/sha2'

password = "pass@123"
salt = rand(36**8).to_s(36)
shadow_hash = password.crypt("$6$" + salt)

And you now have a password hash which you can directly use in /etc/shadow

Be Sociable, Share!

18 Comments

  1. Richard Spindler

    January 31, 2014 at 1:45 pm

    Use unix_crypt ruby gem:

    https://github.com/mogest/unix-crypt

  2. I tried creating a user in Ubuntu using the output of this but it won’t let me login…

    password = ‘foobar’.crypt(“$6$” + rand(36**8).to_s(36))
    `ssh root@#{fqdn} ‘useradd -m -g sudo -s /bin/bash -p #{password} admin’`

Comments are closed.

© 2015 @judepereira

Theme by Anders NorenUp ↑