[No audio]
Hello everyone and welcome to our
new lesson user account management.
In this lesson we will learn how can
we manage user account in Linux file system.
There are a few commands that
we use to manage user account.
The first one is useradd, it is to create a new
user, groupadd to create a new group, userdel delete
a user that is already created, groupdel to delete a
group, and usermod which is to modify a user.
Now whenever we create a new
user, those user management are created,
their record is maintained in three different files.
The first one is /etc/passwd,
second one is /etc/group, and
the third one is /etc/shadow. Now remember.
/etc/passwd is not a complete word password,
it's just passwd. Example to run a user command which includes
all the parameters that you have to define is as follows.
It goes with, useradd -g, with option to add
a group, -s option to give a shell environment,
-c to define the user description,
-m -d to define the user home
directory, and the user itself, and the user home
directory itself, and the name of the user.
Now let's look at our Linux machine
and we will practice these commands and
learn these commands more into detail.
I will log into my Linux virtual console.
[Author typing]
Let's move this a little to the side so we could
see what are the command that we will be using.
Okay, always first thing first, you need
to find out who you are, you are yourself.
Where are you?
You are in your home directory. Perfect.
And what's inside of your home directory just
to confirm you are in the right place. Yes you are.
When you have confirmed this, just do clear screen.
Now we gonna create a user called, let's say spiderman.
Before I create a user, I wanted to add that
user to a group that is, let's call it superheroes.
So in order to use these commands you
have to be root, so become root.
su -
[No audio]
Ok, the first command that we
will run is useradd spiderman.
You hit enter, it gives you the prompt back
which means it did create your user spiderman.
How do we verify if the user is created?
There is a command to check if
users created it's called id spiderman..
It will tell you that there is an id
assigned to the user spiderman, and the group is
created called spiderman and the group's ID so on.
You could also verify by going to the
home directory, the home if you notice that
it created right here, the spiderman.
The next command that we want to learn is groupadd.
I want to create a group, a new group.
The command to add a new group is groupadd,
and I wanted to name it superheroes.
[No audio]
It adds the group.
We could verify it by looking at the
group file which will cover a little bit.
But if you want to see it, you could
just do cat /etc/groups,
[Author typing]
and at the
bottom you'll see it created this
[No audio]
group named superheroes.
[Author typing]
Now I want to delete the user.
I created spiderman.
The command to delete is userdel.
Now if you want to delete the home directory
of spiderman, which is right here, you will run
the command userdel with -r as well.
So it will delete the directory as well.
[Author typing]
So it deleted the user and let's
check if it deleted the home directory.
Yes, it did delete the home directory as well.
So delete that I created and I use it
before just called spider, just for testing purposes.
As you can see here, the next command we
have to do is of course the groupdel.
So let's try to delete the group.
Let's not delete our group
superheroes, we'll create a new group and
we'll delete it just for training purposes.
So let's create groupadd
[Author typing]
nonewgroup.
Let's call this nonewgroup, groupadd, it's created.
We can verify by going to the group file and
see, at the bottom it says no new group.
That's new group ID.
We could delete the new group.
Delete no new group and it's deleted.
We could verify again at the bottom.
See, it's gone.
The next command that we have to learn is usermod.
This command is used to modify the users.
You can run command on usermod to see what it does.
It modifies a user account.
If you notice a appends, it adds a
user to supplementary group. c, the new value
user password, d change the home directory.
So these are the things that you wanted
to do after you create a user.
So we will use this command to add
our user, spiderman.
[Author typing]
Let's see if we have spiderman.
First we delete spiderman.
So let's create spiderman again.
useradd spiderman.
[Author typing]
As soon as you add the useradd
spiderman, it automatically creates its group as well.
If you don't specify, it creates a group
with the same name as user ID.
Now, I wanted to add spiderman to a
different group as well, which is superheroes.
So how do we do that?
usermod -G, what's the name of the group,
superheroes.
And the name of the user that
I wanted to add is spiderman.
Hit enter and it is added.
How do we verify it?
You do cat /etc/,, but instead of doing
the cat and viewing the whole file, how about
we use group command and just type spiderman from
/etc/group file and there you go.
You will see this is the super user group
and spiderman is also part of that group.
This is the spiderman's own group
name and own group ID.
So spiderman has his own group and it also
belongs to a group called superheroes as well.
If you notice one here, when you do ls -ltr,
the group of spiderman right here is still spiderman.
Why didn't change to superheroes?
Because it's actual group is
spiderman will always remain spiderman.
It is part of the other
group as well, which is superheroes.
If you want this to change, then you have
to run the command change group and then you
specify superheroes and then you specify buyer man.
And remember, we have to use our
option to cascade this permission of the
group to every folder of the spiderman.
So let's run this command and now see
if it changes from spiderman to superheroes.
Yes, see now the user is
spiderman, the group is superhero.
So that's how you use these five
different commands useradd, user group ad,
userdel, groupdel and user modification
and the files that it creates information.
The first one is /etc/passwd.
Let's look at the /etc/passwd cat /etc/passwd
and you'll see at the bottom as you add
a new user to the Linux system, it adds
the information of the user at the bottom.
At the bottom spiderman and the spider, the
one I created earlier, both are in there.
The first column tells you the name, the second
one tells you the password which is encrypted.
It just gives you the x.
Second one tells you the user ID and then the group ID.
And right here in between these two columns,
we didn't specify the description so it's empty.
And then here it's a home directory of the spiderman.
And then at the end it's
the shell the spiderman is using.
So that's the description of the /etc/passwd.
Let's look at the description of /etc/group.
In /etc/group you have the first is group name
and then the group password which is the same password
that is used for anyone within that group.
And then the group ID.
The last column that you see here with
a few of them, that means that these
other users are also part of this group.
Then the last file we'll look at is this /etc/shadow.
/etc/shadow file is strictly for
passwords of users that we create.
This does not mean the password right
here, right here is the actual password.
It's just encrypted so we don't see it.
However, it does have some other parameters like the
password does not expire and these many days there
are password length restrictions and so on.
You could view that and man command of creating users.
You'll get more information about /etc/shadow file.
[No audio]
Again, if you are specific about one user.
Let's say you just wanted to know
the information about spiderman in /etc/passwd,
you do grep spiderman /etc/passwd, and
you will only get the information about your
matching criteria which is spiderman line.
Now we will look at the last example, which
is the example that is mostly used in the
corporate environment that they will run one big command
that will take care of all the parameters.
So let's create a new useradd -g to specify
the group, which is we already have a group superheroes.
[No audio]
And let's look at, let's minimize this so
we can move up and view our command.
[No audio]
Okay.
[No audio]
Okay, superheroes -s means the shell
that you want to give.
They're different shells.
There are bin, bash, KornShells,
we will cover that later,
-c is the description,
you have to specify the description.
superheroes, you wnated to create Ironman so,
Ironman,
[No audio]
Character
just a description, nothing more than that,
then -m -d, specify the
home directory which is home/ironman ironman.
[No audio]
This will create a user ironman
with all the parameters we have specified.
And how do we verify?
You just do id ironman, and you'll see that
ironman is there as part of the group superheroes.
And you could also view it in /etc/passwd file.
And you see at the bottom it's there.
Now, one thing that we do have to
cover, every time you have to create a
user, make sure you create its password.
So the command to create a
password is just simple passwd
ironman enter.
Specify the password. And the
password that I've specified, since
password fails dictionary check.
It is based on a dictionary.
You could ignore that as long
as you're running as root.
But if you're not root, then it's going to force you
to change the password that is not based on dictionary.
But again, you are root. You could do anything.
So this concludes our lesson
for user account management.
The basic commands are these five commands
and the files that are used to
manage is etc, passwd, group, and shadow.
[No audio]