Linux post module add user #1595

Closed
wants to merge 2 commits into
from

Projects

None yet

2 participants

@jabra-

Linux post module to add a user.

@kaospunk kaospunk commented on the diff Mar 15, 2013
modules/post/linux/manage/add_user.rb
+ [
+ OptString.new('USER', [true, 'User to add.']),
+ OptString.new('PASS', [true, 'Password of the user.']),
+ OptBool.new('SUDO', [true, 'Give user sudo privs.',true]),
+ ], self.class)
+
+ end
+
+ def run
+ vcmd_exec("useradd #{datastore['USER']} -p #{datastore['PASS']} ")
+
+ #
+ # NOTE: We are intensionally not creating a homedir for the user
+ #
+ if datastore['SUDO'] == true
+ vcmd_exec("echo '#{datastore['USER']} ALL=(ALL) ALL' > /etc/sudoers ")
@kaospunk
kaospunk Mar 15, 2013

This will destroy the target's existing sudoers file which would be a very, very bad thing. Command should be:
echo '#{datastore['USER']} ALL=(ALL) ALL' >> /etc/sudoers

@jabra- jabra- closed this Mar 15, 2013
@jabra- jabra- deleted the unknown repository branch Mar 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment