User & Group Creation (Demo)
Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or
Already have an account? Sign In »

Video Transcription
00:00
>> Hey there, Cybrarians.
00:00
Welcome back to the Linux+ course here at Cybrary.
00:00
I'm your instructor Rob Gals.
00:00
In today's lesson, we're going to be
00:00
discussing user and group creation.
00:00
Upon completion of today's lesson,
00:00
you're going to be able to understand
00:00
user and group creation and use
00:00
the useradd and groupadd commands.
00:00
The useradd command is used to add
00:00
a local user to a Linux system.
00:00
What it actually does is create an entry
00:00
in /etc/passwd and /etc/shadow.
00:00
When it creates an account for a user,
00:00
it starts with the number 1,000,
00:00
and then it increments for
00:00
each additional user you add to a Linux system.
00:00
We're going to see all of this
00:00
in the demo later in this lesson.
00:00
Now, a quick word about the useradd command.
00:00
It actually takes in
00:00
three files when it creates a user account.
00:00
The /etc/default/useradd file is used to create
00:00
a default user variable setting
00:00
or a set of variables settings.
00:00
The /etc/logins.defs file contains
00:00
information on how to create
00:00
group and home directory creation.
00:00
For instance, it may say to actually create
00:00
a home directory for a user by default or not.
00:00
The /etc/skel is a directory that contains
00:00
default home directory files and
00:00
directories in the home
00:00
directory for each and every user.
00:00
/etc/skel is what's known as a global entry by CompTIA,
00:00
and we'll cover that later in this module as well.
00:00
The groupadd command is used to
00:00
add a group to a Linux system,
00:00
and what it does is create
00:00
an entry in the /etc/group file.
00:00
Let's check out these two commands with some demo time.
00:00
[NOISE] Here we are over in our environment in CentOS,
00:00
and we'll use the useradd command,
00:00
but there are a few options to consider.
00:00
If you're going to create
00:00
a user and you're on a distribution where you don't
00:00
necessarily have it set up to
00:00
automatically add the user's home directory,
00:00
you can use the -m option.
00:00
This will create the home directory in case
00:00
the create_home option is
00:00
not set to yes in /etc/login.defs.
00:00
We'll take a look at that in a moment.
00:00
The other option is that you can actually use g or G to
00:00
specify and add the user to
00:00
an additional group when you create the user.
00:00
Let's take a look at a couple of
00:00
files before we get started.
00:00
Let's take a look, for instance, at /etc/login.defs.
00:00
We'll see if they'll let us in there,
00:00
and it does without having elevated privileges.
00:00
Let's take a look for that create home.
00:00
[NOISE] Then we can
00:00
see here that create home is set to yes.
00:00
Luckily for us on CentOS,
00:00
we don't have to specify the m option when creating
00:00
a user in order to add a home directory for that user.
00:00
Let's also look at the /etc/skel directory.
00:00
[NOISE] We're actually just
00:00
going to do an ls on this, ls -al.
00:00
What we can see in this directory is it's going to
00:00
create three files,
00:00
bash_login, bash_profile,
00:00
and bashrc for each and every user.
00:00
The system uses bash as the default shell.
00:00
You're going to see that those files are
00:00
created when we create a user.
00:00
Let's go ahead and do that.
00:00
Let's create a user called test,
00:00
and we'll add it as a user that has pseudo rights,
00:00
someone that can elevate their privileges.
00:00
What we'll do is we'll do that by saying we want
00:00
to do a useradd.G.
00:00
[NOISE] For the user test,
00:00
we're going to add it to the group wheel.
00:00
In CentOS, the wheel group is what
00:00
controls access to be able to pseudo up.
00:00
It's known as being a part of the pseudoers file.
00:00
We can create the user test here with useradd,
00:00
and then we add it to the group wheel by
00:00
specifying the G option to useradd and we
00:00
have to be elevated
00:00
to root privileges in
00:00
order to run this with the pseudo command.
00:00
Let me type in my password for that.
00:00
There we are, we're good.
00:00
Now let's go ahead and
00:00
take a look and see if we could find
00:00
this user's grep for test in /etc/passwd.
00:00
We can see that the user test is created.
00:00
It has an ID above 1,000.
00:00
One thousand and two means it's probably
00:00
the second user that was
00:00
created on this system behind me.
00:00
That's really all that we need to know about using
00:00
useradd over here in CentOS.
00:00
Let's take a look at this in Ubuntu
00:00
real quick because there's
00:00
a couple of wrinkles over there.
00:00
[NOISE] Here we are in our Ubuntu environment,
00:00
[NOISE] we get logged in.
00:00
We're in our Ubuntu environment here,
00:00
and let's just go ahead and clear the screen.
00:00
[NOISE] cd back, clear the screen.
00:00
Here we are in our Ubuntu environment,
00:00
and what we're going to do
00:00
here is we're just going to run
00:00
useradd test [NOISE] as
00:00
well without any additional options.
00:00
We need to be pseudo to do this, of course.
00:00
Let's do that. Now let's go ahead
00:00
and see if we can find this home directory.
00:00
Let's go to home test
00:00
and there's no such file or directory.
00:00
Let's actually do a [NOISE] less on
00:00
/etc/login.defs and we'll see if we can find
00:00
create_home, and that's not found.
00:00
An Ubuntu system does not have
00:00
>> a user created by default.
00:00
>> Instead, what we need to do is we need to specify,
00:00
we want to create a user home directory
00:00
when we create the user using useradd.
00:00
[NOISE] Let's go ahead and remove the user.
00:00
We're going to jump ahead a little bit and use
00:00
a command called userdel.
00:00
I'll talk about that later in this module.
00:00
But we're just going to go ahead and do userdel
00:00
-r to remove test.
00:00
We need to be pseudo to do that.
00:00
There we go. Let's clear our screen.
00:00
Now what we can do is we can do useradd,
00:00
we'll add pseudo to the front of
00:00
that useradd and we'll do -m
00:00
-G. That will not only
00:00
add the user to a group for pseudo rights,
00:00
it will also create the user home directory.
00:00
On an Ubuntu system, if you want to have pseudo rights,
00:00
instead of using the wheel group you use
00:00
the pseudo group and we'll
00:00
add a user called test2 to this group.
00:00
We'll do pseudo useradd mg
00:00
to the pseudo group test2 and
00:00
>> hit Enter and there we go.
00:00
>> Now we can do a grep for test on /etc/passwd,
00:00
[NOISE] and we can see that test2 has been created with
00:00
the user account ID and group ID of 1,002.
00:00
It's in home test2 with
00:00
the bin shell as its default shell.
00:00
Let's go ahead and see if we can get into home test2.
00:00
[NOISE] We go to
00:00
home test2 and we see that that directory exists,
00:00
and if we do an ls -al,
00:00
we see that it actually has all of
00:00
the bash files that we
00:00
found in the /etc/skel directory as well.
00:00
One last thing, let's go ahead and
00:00
take a look at the groupadd command,
00:00
and the group add command is
00:00
much more basic than the useradd.
00:00
Really, the only thing that we want to do
00:00
with groupadd is maybe
00:00
add a number or a group ID,
00:00
a GID, to a group when we're creating it.
00:00
Let's create a group here and
00:00
>> we'll call the group best,
00:00
>> and we'll give it the group ID 1337.
00:00
We'll say groupadd [NOISE] -g 1337,
00:00
and we'll call the group best.
00:00
[NOISE] We need to be pseudo to do this as well.
00:00
Then what we can do is we can do grep for
00:00
best in the file /etc/group,
00:00
and this is the group file where all the stuff is stored.
00:00
We can see that we have an entry for
00:00
the group best with the group ID of 1337.
00:00
[NOISE] We've reached the end of this lesson,
00:00
and in this lesson, we covered
00:00
user and group creation using
00:00
the commands useradd and groupadd.
00:00
Thanks so much for being here and I look forward
00:00
to seeing you in our next lesson.
Up Next
Instructed By
Similar Content