Okay, so we need to create users as well as groups and make sure that the users are a member of the group.
Now, to do that conveniently, I'm going to start by creating the groups. So sudo group
add sales already exists. Well, I'm ignoring that because we are going to need it anyway.
Sudo groupadd account and that creates a group.
And we also need sudo group add users
and that already exists. That's not a problem.
But now I can create my users. So sudo user.
I know that user lynda already exists, so let's not try to create that user again and let's make it user model ag.
User Linda needs to be a member of sales and also of the group users.
So for user Linda, quick check sudo id. Linda is
showing that membership of groups has been set successfully.
All right, sudo user mod g sales users for Lora.
I don't have a user Lora yet, so there's no risk that I'm overwriting any group membership. And that's
why just minus uppercase g is enough. Oops, did I really use user mod? I meant user add.
We also need to do something similar for usernooc, which is also a user that does not exist yet.
So user add users for Anouk.
And then we need another user mod.
So let's do that for user Anna. She needs to be a member of account as well
as users. And also she should not use current assignments and this should be doing it. So
ID on Anna is showing all the groups that user Anna is a member of.
Oh boy, did I forget to set passwords to expire after 60 days? Yeah, I did.
And that means that it doesn't make sense to put it in. Etc, Login devs.
Hey, how about passwd?
PASSWD Help?
Does that have an option to expire the password? Yeah, that's the X option.
So I am going to need X, but I'm also going to need to set the password.
We need input redirection to set the password.
How am I going to do that? Well, I'm going
to use a small shell scripting structure for I in
Anna Nuke and Linda and Laura do echo password, pipe
pass WD standard in on $I and let's also use
minus x60 which is the expiration warning.
And then we need a don on a separate line.
And oh boy, that's telling me only root can use standard in S. What is going wrong? Well, what
is going wrong is that my do command is using echo password and then we have passwd without sudo.
So I need a sudo in front of passwd and there we can see that the password has changed.
Let's analyze what is going on in this iteration we loop over a list.
In every iteration we put the current item in a variable with the name I.
Then the second part is the do part, which is all of this. We
set the password for $I using sudo passwd with this option x60 and also
with this option standard in which is accepting the password from the pipe.
And as we can see, password has been changed for all of that. Now I
would like to know if that has worked out. All right. So I'm going to
use sudo passwds for my random test user and oh boy, that's not very readable.
But here the 60 that's what I'm looking for. That's a password explanation that has been set for user lynda.
Now I also needed to make sure that my users have a home
directory. Now I'm on red hat and on red hat. That's simple.
User home directories are created by default.
If you would have been on Ubuntu, you need useradd M. Without
the M, your users don't get a home directory. And that's all.