0

I have a Ruby script which, using a template, creates a cloud-init yaml configuration to use in order to perform an Ubuntu autoinstall. The script itself should encrypt the user password and, at the moment, I'm doing so using BCrypt:

BCrypt::Password.create("foo")

When I run the autoinstall and it finishes, I can't log in using foo. So, for some reason, the installer or whatever part it is (I would appreciate if someone clarify this to me) is not decrypting the password correctly, probably because it is in wrong format or something like that.

Then, I tried using mkpasswd from the whois package (apt install whois) to generate the encrypted hash as follows:

echo foo | mkpasswd -m sha-512 -s

and the generated hash worked and I could log in with foo after the installation.

So my main question is, how I can replicate the mkpasswd -m sha-512 behaviour in a Ruby script without running a shell process from the script itself?

TIA!

EDIT

I have tried using the following Ruby solution:

salt = 's0m3s4lt'
hash = 'test'.crypt('$6$' + salt)
puts hash

but the generated password doesn't seem to be correct either.

bert
  • 177
  • 1
  • 6
  • I have found out that the Ruby solution posted in the edit doesn't work on OSX but it does on Linux. – bert Dec 23 '22 at 14:27

0 Answers0