In this lesson,
we'll go over creating modifying and deleting users
in a Linux environment.
So the first thing we're going to do
is to view the default settings when we create a new user.
So we going to do that by doing a "sudo" command.
We go "useradd" fetch "D"
Okay let's enter my password
All right so whenever we create a new user
these are the settings that's going to be given to it.
Now in this nest command
we're actually going to go over the settings that are applied
to currently added new users.
So let's get started here we'll go with "less" here,
"etc" "login" dash "defs"
There you go.
See there's more detailed information
about what happens when we're actually creating these users
in their settings.
A little bit of information
about each one of those settings there.
All right want to quit that.
Now the next thing we want to do is also look at a scale file.
Now what allows us to do is see what files will be copied
to the user's home directory when we create them.
So let's look here
ready slash "etc" slash "skel".
Do this.
Now as you see when we created a new home directory
after we create a new user
these are the files that's going to be added to the directory.
So for this example
we're going to create a user called Michael Anderson
Going to add "sudo" here.
Says we need higher level privileges to add and users
"manderson"
All right so there's that.
So now we're going to view
the information of the user.
So we scroll down and we see Michael Anderson was added
at the bottom here.
So reading from left to right we see the first thing
is the user ID.
The next thing is the password but
an "x" is there to represent the fact that
the password is stored in another file
which is going to be the shadow file.
Next line is going to be the user ID.
Next the group ID.
Then we have the user's default directory
and then also the default bash shell when a user logs in.
So that's what that information is telling us there.
So whenever you need to find that type of information out
just use that same command "cat" "etc" "password"
and we'll get all the information we need.
Next we can create another user,
but this time I want to add a comment to
have their name appended to the information.
So we're going to do Chris Mason,
Mason will be his name.
So of course then we go to the "etc" file "password"
I'm going to see the information there again.
So it's right below the Michael Anderson
going to see C Mason again
the next indication is
that the password files is in another file.
The user ID
the group ID
and the comment represents the name.
So Chris Mason
that's a good thing for us as administrators
to be able to quickly find out who the user name belongs to.
And of course the comment
the next thing is the user directory file
and then also again the default bash other one to use
for the user.
We'll clear this here
and just a little bit more practice,
create another account
for user Aiden Riley,
create down here.
Same thing keep it fast
in our up arrow "ralexander"
get up arrow roll quickly.
See they were quickly created there.
So the next thing we're going to do is create a
temporary user account
"useradd" got to create the
dash E stands for the expiration date,
and it's going to be year month day format
that's before it slash year,
along with username
we're going to use R Stanley for our example
Quick let's get to this up arrow.
Now we see the users add at the bottom.
Now a quick way to change the expiration is the
"chage" command.
I'm not sure if I'm saying that right but I hope I am.
Let's do it quickly here
and we can change the expiration date and just say
we want to make it 2022
12 31
Well oops not 13 31
for "rstanley".
Huh? Looks like I have to again.
Use the oh let's do our "sudo" here.
There we go.
So remember the "sudo" exclamation point exclamation point
allows us to call the last command
with the "sudo" command invoked.
So it saves a lot of time.
That's one great benefit of Linux as well.
Another thing we can do is actually see what
the information is.
The "chage" stands for change age,
so it's only dealing with expiration date.
So if we want to see the expiration date for "rstanley"
do it like this.
Also if we want to we can change the
"sudo" change the maximum
days until the user have to change that password.
So "rstanley" here.
So click it back up.
Now we can see the days that the user has until they have to
change their password.
Hopefully everything turns into if and two-factor
authentication in your organization but
currently we still use the password so
90 days is typically the standard for a normal user
and 60 is usually the standard for administrator.
Another thing we're able to do is warn the user when they
need to change their password,
it's going to be "chage" up or "sudo"
Say five days over "rstanley".
Let's see if this is set for
all right.
We're able to successfully configure every single
one of the options for the password expiration.
The next thing we're going to do is modify user information.
So this is we're just going to modify the user's account name.
So we go "rstanley" again
and this time what we're going to do is
we're going to change the user's name,
but the syntax is going to be dash "L".
We're going to use the name we want to change it to,
and then the actual name that's currently in the system.
So we're going to change it to "rstanley1" from "rstanley".
We're going to verify the information was changed.
"etc" password file.
And we can see at the bottom is now "rstanley1"
when it was prior "rstanley".
So that's some of the information we use.
There's more documentation of course,
if you want to go to the man
and you can see the
all the options that are available for user modification.
Now as an administrator sometimes it might be
necessary to lock and unlock users
a quick way to do this "sudo" password
and use dash "L" use "rstanley" here.
When we see they're locked
now we want to unlock it just simply dash up
change this "L" to "U".
And now we see unlock Stanley's account.
So again very quick very easy.
Now the graphic user interface it might be a little easier
but this is much faster and much more powerful.
So learning command line is very important.
Now in this lecture we'll continue to focus
on modifying users in Linux.
So the first thing we want to do just a little refresher
let go back and check these user accounts
and the "etc" password file.
Now as you see J Kelly at the bottom
A Riley R Alexander and R Stanley.
Again note the X after is showing
that the password is stored in a different file.
So the file in question is going to be the "sudo" "cat"
because we have to have permissions to get to this file
and that's going to be the shadow file.
The shadow file stores the hash of the password
not the actual password itself.
And you can see here noted for mine and A Riley's
that the password is there,
but again for R Alexander and R Stanley,
it shows the exclamation points again
identifying that there is no password set.
So the next thing we want to do is go through
and set those passwords right now.
So it's administrative function
so we need to set password.
We're going to use "ralexander".
All right we're going to set a password for them.
So it's giving us an error letting us know
that it doesn't pass the dictionary check for this example.
We're just going to let it go.
So we want to make sure it went through here,
just go back to the shadow file
now you see R Alexander has a hash
of his password shown in the file.
So just for more practice,
we're going to do one more for Stanley.
Use the up arrow,
"rstanley" password.
Try to do a better password.
Little bit more secure
see what a fuss that was
All right.
No fussing yet.
All right looks like we're good to go there.
Okay R Stanley has a password set now.
Now next thing we going to do is modify the user account
just by adding a comment,
really stating their name.
So we're going to go with R Stanley first.
We're going to use the "usermod" command.
So we're just going to dash "C"
we're just going to add a comment
give name say Ramone Stanley
it's going to be his name for this example.
And got to make sure we add it to the Stanley account.
Press enter,
let's go check that again.
Again we'll go to the password file to make sure we
see information about the users in question.
So here we go.
"Password" so now we're seeing
at the very bottom R Stanley
Raymond Stanley so the comments again,
are good information for an administrator quickly
see who a user is.
That's what it's mostly used for what you can add
all type of other information of course.
And so we'll stick with Stanley in this example
and this time we're going to actually just look
and see the information for Stanley's password.
But to do this we want to used the command
from earlier change age is what it stands for,
"chage" again I think I'm saying that right.
Going to do "rstanley"
and now we can see all the information about the password.
The last time the password was changed
when the password expires,
if it's inactive
when the account expires
the minimum number of days between password change
maximum number of days between password change.
The number of days before a warning is set to
let the user know that they need to change their password.
So this is a quick way to get all that information.
Now we're just going to test out one of these commands
we're going to go through
and we're going to actually change the expiration
of Stanley's password
change to 2026.
So also just remember of note
you have to use the year month then day.
Let's see
Oops forgot to add to to "rstanley".
There we go.
"rstaley" again and now you can see we've
changed the count expiration to December 31st, 2026.
And again we're just going to use another command.
We're going to lock out Stanley.
So this be the "sudo" password dash "L".
Then just stands to lock the account
and then if we ever want to unlock Stanley the same thing
go through here.
The unlock key the "U"
and now we've unlocked Stanley's password.
Now the last thing we're going to do is user delete.
Now it's very common that going to delete a user.
Maybe the user leaves the organization,
fired terminated.
So quick way to do this is just a simple "userdel".
So we're going to use "sudo" "userdel" all right
now I'm going to verify that that account is gone again.
"etc" password file
and you see R Stanley is definitely gone.
Now one thing to note
when you're deleting an account
it doesn't delete the directory that's stored
along with Stanley.
So if we check really quick we'll see that
we should still have R Stanley's information.
As far as this directories files that are stored
still in the system.
So again if you want to delete everything about the user
you're going to have to use the dash "R" option.
So who can I test that out with
A Riley so let's try that,
"sudo" dash "ariley"
All right.
Now same thing just check make sure she's gone.
All right.
A Riley has gone.
Now let's check to see if the directory is also gone.
Yep directory is gone.
So that's a quick note how to wrap up
and delete users also to modify their accounts
change the expiration dates,
adding comments things of that nature.
So that's all for now and I'll see you
in the next lesson.