In this video you learn about users and how to create them on your
Linux hosts.
Our plans to explore how users are managed inside of Linux. This
will cover creation modification and deletion.
We will discuss the three types of users root standard and
service. You create a new user and set a
password so that you can log in as this user.
Finally, we will briefly cover a special command called sudo
which will give you your user elevated permissions. Let's get
started.
So here we are back in our terminal and we're going to be talking
about user management.
Mostly cut. We're gonna be talking about user management.
Mostly user creation, but we're gonna go through all
the steps needed to manage users. So Lexus consider
what a multi-user operating system and this means
that you can have multiple users doing different permissions and tasks
they can all log in.
So but there are three main types of users that
your system can have. The first user
is what what we call Standard. It's just like
the ec2 user that you're logged into right now.
There's the root or administrative user is a
user that has elevated permissions that can perform special tasks
or commands on your system that
only somebody with that has root privileges
can do and then the third one is a system or
you may have it as a service user. This user does
not have the same behavior as a standard user but it it's used
for specific tasks like running a spit a
process as a user. This user would not log into
a system. It would not have a home directory and this
is done mostly for security reasons since you
don't want a
Process being run as a user having full access to the whole system.
Okay. So like I said in the intro we're gonna create a user
we're going to create a user called Akira. Feel free
to change the name if you'd like, but just know going
forward we're going to use the name Akira. This user
will have their own home directory and a group
like we saw earlier when we took at ec2 user.
So to do user Linux management.
There are a few commands that you're gonna work with one is
called.
Add user Oop There we go. Add user.
The next one is called password.
The next one after that is called user mod.
And there's another one called user. Delete.
Okay, so let's talk about the add user command. So
the add user command creates a user with
some defaults already set for us like home directory your
shell login and those sort of things the password command
sets a password for a user.
The user mod command allows you to modify an
attribute about an already created user.
Now we will not use the user delete
command in this in this course in this video because we're going
to use this user that we create today in future videos. So but
just to know that it does exist.
So one thing we're gonna take a little detour really
quick before we start creating users. So creating users on an
Linux host requires root or elevated permissions.
And you think about it. You wouldn't want just normally uses
being able to modify or create users without some sort
of elevated permission. So, for example, when we
log in here to our Amazon Linux ec2 instance, we log
in as the ec2 user. So ec2 user already out
of the box has some super powers and these
superpowers are called sudo which sudo
or what it stands for is super
user do
And if you prefix any command with sudo and
you have those permissions your users allowed
to what it does is it affords you temporary elevated
permissions to run that command as
you were like as you were a root user. Now, these
permissions can be fine tuned. They
can be set is a configuration file that helps control this
and that file is called sudoers and
that file is located under your Etsy
directory. Remember slash Etc is where all the configuration
files are kept and we can just look to
see that it's still there.
And as you can see, it's there. It's owned by root.
I'm not gonna go into this file and go into the the configuration
of adding use of sudoers, but I wanted
you to know it exists. And this is how we can do these things as
the ec2 user how we could perform administrative task with
the ec2 user.
Okay. So let's go ahead and clear the screen and let's go
ahead and create our user Akira. So in your terminal
we're gonna start out with the sudo command.
And then we're going to use the add user command.
And then we need to say the user we want to create and in
this case. We're just going to use the word the name Akira.
So we hit enter no errors
are come back which tells us that the user
was created sex successfully, but let's go ahead and
verify that so one way we can verify that
is we can look in the file system. And if
you remember the home directory in the file system, which is
slash home. This is where our ec2 user
home directory was and as you can see now
We have a Kira.
Is a directory inside the home.
We also have a group called Akira.
And a username called Akira just like our ec2
user.
So when users are created they are put into
a file called Etc passwd or
you can just say password even
though it's missing an o in it, even though the name
says Pat is password in it. There's actually no password
stored in this. This is just a database file of
all the user accounts on a system.
And this is another place that we can go look to
see our user that was created. I want to show you this file because
it's important when you're managing users to be
able to know where they're being kept in any changes
you make to them you can see them.
So I'm gonna clear the screen and we're going to use the cat command again
to go ahead and print out the contents of our
Etsy password file.
So
Basically here, you've got all the users on the system. Some of
these are
root users like the three types we talked about so you
have a root user here.
and if we come down to here you have a sshd
user which is what the
SSH server runs as
And then you have normal standard users like ec2 user.
Now. If you look down here we have the
new user. We just created Akira and so as you
can see there's a format to each line here and we're going
to call these fields. And so the first field is Akira,
which is the username that this person logs in
with
The second field is it is an X and this x
is a placeholder for what the password is.
There's no passwords in this file. So you just get the X this
is kind of a leftover from older days of Unix and
it's not used anymore because passwords are kept into a
secret kept file.
As you can see here. The next field is 1001 and
this is the unique user ID for the
user Kira and each user will have
a unique ID on a system. They start at one number and they just keep incrementing
the more users you create. The next field is 1001
again, and this is the unique group ID,
which is we know that group called The Cure was
created.
As you can see here in between these two colons, there
is nothing in there. This is the metadata for
user they call it geicos gecos and
what this is kind of a leftover from
the old days of teletype and terminal sharing and this
was stuff that like username.
Room number those sort of things. It's
not used as much anymore. But it's a good place to put
some a full name as the user or maybe a comment of
what that user is doing as you can see here in our ec2 user.
It was created with a comment in
here saying the ec2 default user. Okay, the next
field over here the slash home slash Akira, this is
our home directory for Kira. You can put a
home directory anywhere most distributions Linux distributions
have a standard where they do it under slash home and ours
is that is the default on the system as well.
The last field over here is our shell and
if you remember the slash bin is where commands executables
can be run both by standard uses
and root users and Bash is just a
shell and a terminal that we log into and we
perform tasks and run commands in and we
will actually in the next section. We're going to go over bash and some
bash scripting.
So that is the basic fields of a user.
I want to pay attention to this empty metadata about
the user. We're actually gonna when we modify the user we're gonna
we're gonna change that and put in the user's full name, but we'll come
back and look at that in a minute. Okay, so let me clear the screen
here. And so to make this user active we
need to set a password. So with this we could log in
and out as this user if we want to so to set
a password for user use the passwd command.
But because we're setting a password for user that
we are not that is not us and we do not own you have
to use pseudo in front of this because you need elevated permissions
would make sense because you don't want any normal user being able to
set passwords for any user on the system. It is a root administrative type
task. So we're gonna set we're gonna
type sudo password Akira and
then we're gonna hit return and what this is gonna do is gonna prompt us twice for
a password. So please use something that's
strong make sure that you remember this
password or you have it in a password
manager or written down somewhere obviously don't put on sticky notes, you're
gonna need this password at the end of the video
when we go to validate that our user is functioning. Okay, so
hit return
And I'm prompted for the password.
And so I entered my password and I'm greeted with all authentication tokens
updated successfully which just means
that both passwords match and it was stored in the password hash
file.
Okay. So let's go ahead and with the
password of the way, let's modify.
The user Kira and let's go ahead and add the full
name to the to the Etsy password file.
So once again we have to use sudo because this is
a administrative task and then we're gonna say user mod
and then we're going to use the dash C the dash
C. Which means comment for the flag and I'm
gonna put a cura's full name.
And we're just gonna say Smith here could been Jones.
And we are going to then pass in
the user. We want to modify in this case is Akira and
we hit enter.
So really quick before we go validate this I just want
to show you a quick tip. If you are unfamiliar what
flags to pass Unix or
Linux commands.
You can either a look at the man page like we did you could
do. Yeah, man user mod and that'll give
you all the write up in documentation on
that command itself. But if you wanted
to do something a little bit quicker you can do user you
can do user mod.
But do not pass it any Flags.
And most Unix and Linux commands will just print
out its help page if you will and if we
do hear we can see that a prints out all the flags. We can type it
tells us that user mod. It takes options and
then whatever the user name that we're
gonna use and here you can see
We passed this set Dash C with the comment
which adds new values of the gay Coast
field which we saw on Nancy password file. So I just
wanted to show you that quick thing in case you're wondering how are you
how am I supposed to figure out all these flags because there's so many of them.
Okay, so make clear the screen. Let's go back and let's
cat out the Etsy password file again,
and let's see what's changed.
So as you can see here at the bottom of the file now right
in this field where it was nothing before we now
have Akira Smith. We have the full name. And so
this is a good way. Like I said to add full other
metadata about the user that may be helpful for you as the ministrator
down the field to look at.
Okay.
so
the only thing left to do is to actually see if we can
actually log in we are using the new user. We
just created so let me clear the screen.
And we are going to use a new command, which is
called SU.
And this command stands for switch user and
what we're going to do is we're going to switch user. We have to
use a dash there.
And then we're gonna say switch user to Akira.
And so what's once you hit enter it's gonna prompt you
for a curious password. So this is where you're gonna need the password you to
centered and if it's successful we should log into the home
directory of a cure which is slash home slash Akira.
So let's go ahead and try it.
And there we go. We're logged in as Akira and
to prove that we are in a cure as directory we
can do an LS and if you notice that there's no
engineering directory in here like we did for the
ec2 user.
So there we go. We have a functioning new user
on our Linux hosts. Let's jump
back over and let's do a recap of everything that we learned and
talked about in this video.
Okay, so you learned about users and how you
can manage them Atlantics?
We talked about the three common user types root
standard and service you use the
add user and password commands to create a user
and set its password.
You also introduced to the user mod command to
modify. Your user after was created. You also learned
about the user delete command. If you
ever wanted to remove a user from the system, even though we did
not demo it here.
Finally, we did a brief overview about sudo or super
user do which provides a safe way
to give a user special permissions to perform tasks. We
will use pseudo often in the rest of this course.
In the next video, you will learn about Linux groups and
how to manage them. See you soon.