Skip to content

Create linux users with ruby

You are writing a ruby script that needs to create linux users. You are making a system call to useradd and everything seems to work fine, but when you try to log in, your password does not work.

Here’s a ruby-encapsulated system call that will create a user  with the correct password:

group = 'exciter'
user = 'metalmouth'
pass = 'niiiianianiaaaaah'

`sudo useradd -p #{pass.crypt("JU")} -g #{group} #{user}`

So the gotcha is that you have to pre-encrypt linux passwords before passing them to the system.

Categories: Code, Tricks.

Tags: , ,

Comment Feed

4 Responses

  1. Made my day, thanks

  2. Thank you! this helped me so much.

Some HTML is OK

or, reply to this post via trackback.