- All right, so we need four users,
but we also need password settings,
and we need these users to be a member of groups.
So you know what I'm going to do?
I'm going to start with /etc/login.defs
because here it really makes sense if we take care
of the defaults before we are getting started.
And I am looking for PASS MAX DAYS.
I'm going to set the PASS MAX DAYS to 60.
There we go, 60 days.
Is there anything else that we need to do here?
Well, wasn't there anything about user home directories?
Let's check it out.
Not here,
but there, CREATE HOME, yes.
So that's good.
We create user home directories.
That means that we are done here.
Now if I may give you an advice,
if you need to create users,
and these users need to be a member of secondary groups,
then you better create the groups before the users.
Because otherwise, you first create a user then the group,
and then you need to modify the user
to be a member of the group, sounds like too much work.
So sudo groupadd
sales to add a group with the name sales.
Already exists, that's okay.
And sudo groupadd account
to create a group with the name account.
I also need a group users.
Don't we already have a group users?
Let me use grep user on /etc/group.
That'll tell us.
Yeah, we have group users.
So that is okay.
And now I can use useradd,
useradd linda.
I already have linda, so let's skip linda for now,
and let's do laura, minus uppercase G,
and laura needs to be a member of the group sales
as well as the group users.
Everybody needs to be a member of the group users.
And that should be doing it,
if you use sudo, of course.
There we go.
Same command with sudo this time.
Let's also create user anna.
User anna needs to be a member of the group account.
And there we go, user anna.
And user anouk, also same groups as user anna.
So that's a simple modification.
For user linda, who already existed,
I need to use usermod, usermod -aG
sales on linda.
What is that?
Well, usermod is modifying users.
Uppercase G is for secondary groups.
But if you just use uppercase G,
then you are going to create a new list of secondary groups.
That would overwrite the current secondary group assignment.
That's not what we need.
And that is why we are using usermod -aG,
which is using uppercase G in append mode.
And obviously we need to do sudo again.
There we go.
Now we are almost there.
Didn't we need to do anything to ensure all users
get a home directly in /home?
Well, not on Red Hat.
On Ubuntu,
you need useradd -m, -m to create the home directory,
but here if I use ls on /home,
I can see home directories for all of these.
Can't we do that in a smarter way?
Of course we can.
We need a small shell scripting style iteration,
for i in linda, laura,
anna, and anouk,
do echo password,
pipe, sudo passwd,
minus minus standard in, $i, done.
And there we go.
This is easily looping over the different user name.
And for each element in the user name,
it's temporarily putting this element in a variable
with the name i, and then it's doing the do thing.
And in the do thing, this is what is done.
Echo password, pipe, sudo passwd,
dash dash standard in, $i.
$i refers to the user name that's currently treated.
And as you can see right here,
it is walking over all these user names one by one
to update the passwords automatically.
This is how you do it.