Create users during provisioning?

Latest response

Has anyone successfully created OS users during provisioning of a RHEL instance? I'm finding the docs vague on this, and web search not much help.

I would like to provision RHEL 7 and create three users, one of them admin.

Thanks,
DL

Responses

Hi David,

Are you talking about kickstart? if so, a simple option:

group --name=myuser --gid=5555
user --name=myuser --uid=5555 --gid=5555 --gecos="My User" 

Regards,

Dusan Baljevic (amateur radio VK2COT)

Hi David, In Satellite Web UI > Host > Provisioning Templates > I cloned the Satellite Kickstart default. And then edited my own copy, leaving the original there in case I killed it and needed to revert. Not sure if the location is important, enter the commands as per Dusan.

I added after

rootpw --iscrypted <%= root_pass %>

The following, replacing anthing I make as with real details

# <YYYYMMDD>:<initials>: Create Groups and Users into this provisioning template
group --name=<group> --gid=5555
user --name=<user> --gecos="<Comment/Description>" --uid=1000 --gid=1000 --password=<HASHED PASSWORD> --iscrypted
# end: Add Groups, Users

And for the hashed password I used

python -c 'import crypt,getpass; print crypt.crypt(getpass.getpass())'

Regards, Peter

Thanks, Dusan and Peter. Peter, I've barely touched python - does that line of code just fetch the hashed password of whoever runs it?

Hi David,

You got it right. Python snippet simply prompts you for a password and generates the hashed string for it that you use in the kickstart config.

As a side note, in kickstart file itself you can also have post-exec scripts and include lines like this for initial password (this is just for learning experience):

echo somepasswd | passwd --stdin myuser

Regards,

Dusan Baljevic (amateur radio VK2COT)

Sorry, yeah, not much python myself. It will simply prompt you to type a password and from that output the hashed password.

# python -c 'import crypt,getpass; print crypt.crypt(getpass.getpass())'
Password:
$6$rEfz8NAJ3UhqCbke$hPGcmUcTrY7XWJWbQgekJF2EyEsPF//MR12/jGO/XXv3m4QVUe7nmZixERbXa4mZWzfT/PuJiAi451.Zjc4YG0

And then I just copy and paste that into the Satellite provisioning template.

Another method for adding a user in kickstart with a crypted password

Red Hat solution for sha512 password https://access.redhat.com/solutions/221403

[root@myrhelsystem ~]#  python -c 'import crypt,getpass; print crypt.crypt(getpass.getpass())'
Password:
$6$jf8NE9SGx2HORcaU$lm7gfu2mPQ7VoLFJzraRf1gLb92Hp6JKeZ3Fqf4U4SunG9ZbFfrbMpCirDi0SIfw0ZNILRAgvoqWZCVbosTZ70

### insert the below into your kickstart file, or Satellite provisioning template
#note the next line is really just one line!
user --name=myuser --password=$6$jf8NE9SGx2HORcaU$lm7gfu2mPQ7VoLFJzraRf1gLb92Hp6JKeZ3Fqf4U4SunG9ZbFfrbMpCirDi0SIfw0ZNILRAgvoqWZCVbosTZ70 --iscrypted

Regards

RJ

By jove, it works! First attempt did not - I had placed it later in the Satellite provisioning template, and it spat back "user command not found" - but placing it right after the rootpw command, it worked. I don't understand why, but that's what happened.

I think I'll try turning it into a snippet that creates the three users I want on every OS instance.

Thanks to all.

Hi David,

It is so nice to see someone happy and community coming together to help.

By the way, I like your phrase "By Jove". It is not used commonly these days. I read lot of books to learn English when I was young, so your phrase reminds me of them...

Have great weekend everybody, sent from "down-under" (Sydney, Australia).

Dusan Baljevic (amateur radio VK2COT)