Please go to EliTheComputerGuy.com in order to view schematics, code,
and more for the projects that you are learning about.
Welcome back.
So in today's video I'm going to show you how to add users, how to delete users,
and then how to modify user profiles.
So doing things like changing passwords for users.
Now the important thing to understand in the Linux world is that doing these types
of tasks in the Linux world only seem complicated because it's so much simpler
than the Windows world.
So if you're used to dealing with Windows administration, especially in an Active
Directory environment, there are so many amazing things that you can do with user
accounts in the Windows world, right?
And so when you go to Linux, you're expecting to be able to do all those
amazing things in Linux, and then you think you just don't know how to do it,
and then you get frustrated, and then you give up.
The reality is that in the Linux world, basically how users work, how groups work,
and how permissions work is a hell of a lot simpler than the Windows world.
So if you overthink it, if you try to make it more complicated than it actually is,
that is going to run you into problems.
So I'm going to show you how to use the add user command.
So basically using the add user command allows you to add users to the system.
I'm going to show you how to change passwords, so how to change your own
password, and how to change passwords for somebody else.
I'm going to show you something called the password file or the password file in the
ETC directory.
This actually contains all of your user accounts, so you can go there and see what
users are in your Linux system.
So you can make sure if they're there or if they need to be removed.
I can show you how to use something called a chfn command.
So basically what this is going to do is it's going to allow you to change the
profile of the user within Linux.
I'm going to show you something called usermod.
We're not actually going to use usermod today, but usermod is a nice little
command that allows you to do things such as lock user accounts.
So that might be useful for you.
Then I'm going to show you how to delete a user.
And then one of the important things, a cleanup task, is I'm going to show you
then how to remove the user profile directory that is created when Linux
creates a profile to begin with.
This is one of those important things that again this can become one of those
maintenance issues where when you create a user account in Linux, it creates a folder
for the profile in the home directory with all the profile information.
One of the weird things in the Linux world, kind of like not really sure why
that happens, I suppose that there's a reason, is that when you delete the user
account it doesn't even give you an option for deleting that profile directory.
So you simply have to go and then actually remove the directory manually to make sure
you don't get bogged up with a whole bunch of old user directories that aren't of any
value anymore.
So with that, let's go over to the computer and we'll show you how these
commands work in the Linux world.
And again, the important thing to remember here is that Linux when it comes to users
is a lot easier, a lot more simple than the Windows world.
So if you're running into problems, the issue most likely is you're
overthinking things.
And so just try to roll it back a bit, try to think about doing things a little
bit more simply, and you'll most likely be able to figure out what you need to do.
So with that, let's go over to the machine and I'll show you how this works.
So here we are at my Ubuntu server.
Again, we're using 18.04.3 for this demonstration, but add user has basically
been the same for decades and will most likely be the same for another decade or
two.
So you really shouldn't run into any issues if you're using a different version
of the Ubuntu server operating system.
So with that, I'm going to log in.
So my main account that I've been using is this account called Bob and the password
is 1-2-3-4-5-6 because that's what makes my life better.
We log in and we get the normal screen.
So what I'm going to do is I'm going to do clear to clear the screen so that we get
back to a blank screen.
So the first thing that I want to do here is I'm going to do an add user.
So all I need to do is sudo, super user do.
So we need to escalate our privileges up to that root level ability to do things.
And then we're going to add user.
Nice, nice, simple command.
Nice, simple Linux command.
You're going to add a user and the command is add user.
You can't make it any more easy than that.
And we are going to add a user.
Let's say Tim.
We're going to add the user Tim and then we're going to hit enter.
So it's going to ask us this right here.
We're asking for the password for Bob.
So it is important when you're doing this you're going to be asked for passwords in
different places.
And so you do have to keep in mind what password they're asking for something.
So for this they're asking for my password.
And so my password is 1-2-3-4-5-6.
Hit enter.
So adding Tim has created the directory for Tim.
So on and so forth.
So here it's creating home directory.
So Tim's profile directory is going to be home Tim.
Then it's asking now enter new Unix password.
At this point it's now asking for the password for Tim.
What is Tim's password going to be?
Again we're going to make this simple 1-2-3-4-5-6.
Going to ask to retype 1-2-3-4-5-6.
And we're going to hit enter.
So from this point it asks us for some profile information.
Now it is important here, depending on what you're doing with your particular
server, you can leave this all blank.
None of the rest of this matters.
The only thing that really matters is the the username and the password.
That is what is actually useful for Linux.
The rest of this is basically little housekeeping things.
So you know if you're building the server and these user accounts are actual
employees in your company, you may want to plug in information here.
But honestly again if this is simply a web server and you simply need a couple of
user accounts in order to do different type of maintenance tasks, I would argue
more or less to leave this blank.
But we can do go here we can simply say this is Tim McCoolio.
Tim McCoolio.
That is his full name.
Then it's going to ask for his room number.
I'm going to make his room number 2.
It's going to ask for his phone number 111-222-3333.
Home phone number 222-333-4444.
And then our other...
hey mom... you know whatever other information.
Again this is one thing if you do create a user account for things like services,
something like that, in this other here you might actually want to just put a
comment of hey this user account was created for email services, something like
that, because that can be useful.
Again one thing you have to be remembering whenever you build a Linux system,
whenever you build anything for infrastructure, it's not about you
maintaining it.
It's not about whether you can maintain it a year or two from now.
It's about when you leave the company or organization and somebody else has to come
in behind you and figure out what the hell is going on.
Can they know what's going on?
So if you put a comment in here, again for any kind of user account you're
creating for services, that can make their life a hell of a lot easier.
Not to mention, I'll just put this in there, not to mention that a lot of times
you forget things that you don't think you're going to forget.
So three years from now when you come back to maintain this system, having put your
own notes there might actually make it a little more helpful for you too.
So anyways, the other is just simply for a note thing.
We hit enter.
Is this information correct?
We hit yes.
And then we simply go back to the prompt.
So that's really all there is there.
So we do clear.
One of the things we can look at now is we can look at something called the password
file.
So we can do vim.
So we're simply going to use vim.
So I'm not doing sudo vim because I do not plan to edit the password file.
That's an important thing.
Remember, sudo vim will allow you edit the password file.
For a lot of these files, I just simply use vim.
It will open it up as a read-only.
And again, this is something that can be useful just to make sure you don't fat
finger something.
If you open something as read-only, then if nothing else, you know you can't
screw it up, right?
So I'm going to open it up as read-only.
So forward slash is the root directory.
Etc is the folder under root.
And then there's a file called passwd because of course it is.
They can't just make it a password file.
Don't be ridiculous.
And then we're going to hit tab.
And so we open this up and yay, we get a whole bunch of information here
that probably looks like gobbledygook to you.
But these are in fact all of the user accounts that are currently on this Linux
system.
And it gives you some information about these accounts.
And again, one of the things you'll notice is daemon, bin, sys, games, lp,
news, right?
All of these user accounts are used for specific services in the Linux operating
system.
And so again, it is a good practice to think about that.
If you create a specific user account to do a specific task, it makes it harder for
the system to be hacked, right?
Again, you think about it with hacking and basically hackers will use all the
permissions that are given to something, right?
So if you give one user account a whole bunch of permissions, again, that whole
thing, if you give one user account root permissions to a server, then if a hacker
can compromise that one root account, they basically own the server.
The same is true with giving user accounts lesser permissions, right?
If you give one user account permission over FTP and permission over, I don't
know, SMTP and permission over a number of different things, then if a hacker can
compromise that one account, then not only do they get access to FTP, but they also
get access to SMTP and they might get access to MySQL and they might get access
to enough things that they can then hack around and get access to the whole system.
So if you create specific accounts to do specific tasks, that is one way to try to
make the system a little bit more secure.
But if we go down here, again, we can take a look.
And so in blue, there's a light blue on the left hand side.
These are the user names.
These are the user names for the accounts.
And if we go all the way down, we can see Bob.
So Bob is the account that I use.
We can see the full name of Bob is simply Bob.
His home directory is HomeBob.
I've been bashed.
Don't worry about that.
Then I created an account Ralph.
Just screwing around, create an account Ralph.
Again, we go over here, see his full name is Ralph, HomeRalph.
Then we come down here to Tim, that account that we just created.
And we go over here, Tim McCoolio.
He's in room number two.
His phone number is 101.
His home phone number is 222.
And the comment is, hey mom.
And again, so that's something to be thinking about with using that little
comment there.
Again, if you create a specific account in order to do something, somebody could come
into the password file and go, oh, okay, so this account was created to
do X, Y, or Z.
And so that's really all there is to the password file.
And this is an easy way to go in, see if an account has been created,
and then go from there and take a look at the information.
So with that, since this is VIM, all we're going to do is we're going to do
colon Q.
So colon Q will quit us out of VIM.
Since we haven't done any modifications, we don't need to do a force quit.
We don't need to do a save quit because we haven't modified anything.
So we can simply do colon Q and we can get out of this.
So there we go.
So now we are back at the Bob screen.
And so it's important to understand.
So if we take a look at this, we are in the user account Bob at server.
So this host name, the server name of this server is server.
And we are at the Bob user account.
So one thing just to take a look at is we can exit out of the Bob user account.
And come back here.
And so we created the Tim user account.
So I can log in as Tim.
You can ask for the password.
1, 2, 3, 4, 5, 6.
Hit enter.
And yay!
Now I am logged in as Tim.
Now the important thing, again, something to be thinking about is when
you're logged into a system.
So if you sit down at a system and it's already been logged in, again,
horrible security procedure.
Don't do that.
Always log out of the system.
But just in case you sit down in the system, maybe you're doing maintenance
tasks before, you forget who you're logged in as.
If you come up here, this is your user account at the server name.
So you can just verify that you're using the right user account.
From here, if I want to do something such as change my password.
So now I log in as Tim.
So I give Tim the default password.
Everybody has the password 1, 2, 3, 4, 5, 6.
So Tim, when you log in, your password is 1, 2, 3, 4, 5, 6.
But you need to change your password once you've logged in.
So all Tim has to do is use the password command.
So the password command is what allows you to change your password.
So you hit enter.
So it asks for the current Unix password.
So I have 1, 2, 3, 4, 5, 6 is the current Unix password.
I hit return.
It asks for a new password.
So let me do 1, 2, 3, 4, 5, 6, 7 is the new password.
Retype 1, 2, 3, 4, 5, 6, 7 is the new Unix password.
Bad.
New and old passwords are too similar.
Well, there you go.
I actually wasn't expecting that.
But hey, that just goes to show you there is a little bit of stuff there in Linux.
So enter new Unix password.
I don't know.
We'll do 1, 6, 5 times.
1, 2, 3, 4, 5, 6.
New password cannot be a palindrome.
Okay.
Well, this is getting a little more interesting here.
Let me just P-A-S-S-W-O-R-D.
P-A-S-S-W-O-R-D.
Password updated successfully.
Oh, there you go.
So now I changed my password to password.
So again, these are the little stupid things that you can run into the Linux
world.
That is a lesson for you that I wasn't expecting to give you.
So just something that you may run into.
So the command in order to change your own password is P-A-S-S-W-D.
You put in your old password and then you put in your new password.
Can't be too similar.
Can't apparently be a palindrome.
Like seriously, where the hell did can't be a palindrome come from?
That's default.
I didn't do that.
But anyways, then you got to plug into something that Ubuntu gods like,
and then your password is changed.
So from here, let me show you how to change a password for a user.
So we're going to exit out and we're going to log back in as Bob.
So Bob is our root, is our administrator account.
One, two, three, four, five, six.
And so now let us change the password for Tim.
So again, let's say we need to get into Tim's account or whatever else.
And so if you're here in order to change the password for the user, we're going to
do a sudo, super user do, escalate the privileges.
Then we are going to do P-A-S-S-W-D for password.
That is the command.
And then we're going to do the user account that we are changing the password
for.
Then from there, we simply hit enter, enter a new Unix password.
And so for this, all we're going to do is the new password for Tim.
And so this is Tim's password.
We're just going to put him back to one, two, three, four, five, six to make my
life easier.
One, two, three, four, five, six.
Type, retype one, two, three, four, five, six.
Hit enter.
Password updated successfully.
So if you want to change your own password, the simple command is
P-A-S-S-W-D.
If you are the root user, the administrative user, in order to change
the password for somebody else is sudo password and then whatever the user
account name that is for Tim.
Now let us go and take a look at the change, basically being able to change the
profile if we want to change things.
So with that, let's clear the screen again.
And for here, we're going to change Tim's profile.
So we're going to do sudo C-H-F-N.
And then we are going to do the user account name.
So we're going to do Tim.
And so when we do this, basically it comes up here.
And so it gives us the full name.
So it's Tim McCoolio.
And we're going to leave Tim McCoolio as it is.
And then it's going to ask for the room number.
We're going to say, well, we're going to swap him over to room number seven.
It's going to ask for the password or the phone number.
So we're going to put it at 888-777-9999.
We're going to go down the home phone number.
Let's just say that's the same.
Any other information, we're just going to leave that the same.
And then there we go.
If we go and we take a look at that password file.
So we're going to take a look at VIM, E-T-C-P-A-S-S-W-D.
We can now open this up.
And as we can see, this user profile information has been changed for Tim
McCoolio.
He is now in room number seven.
His phone number is now 888-777-9999.
So on and so forth.
So you can see that information.
So with that, let us get out of here.
Again, colon q.
That is what will quit us out of VIM if we have not made any modifications.
Let me do clear to clear the screen.
And now I just want to show you a little bit of the user mod command.
So with the user mod command, what we're going to do is we're going to do sudo.
Then we're going to do user mod.
And I'm not actually going to do anything here.
I'm just going to do sudo user mod tim.
And when you do this, you're actually going to get kind of like a man page.
It's going to give you some information for the user mod.
And from here, you can see the different options to be thinking about with user
mod.
And so when you take a look at it for usage, so you have user mod, then you put
in options, then you put in login.
So how this normally should be is sudo user mod and then hyphen c, hyphen d,
hyphen e.
Put all the options in there and then you put in login information.
We're not going to worry about that right now.
One of the things I did want to show you with the user mod command that I do think
is interesting and something that you might want to look at is you can actually
lock the user account.
So again, one of the things to be thinking about is you create user accounts.
Sometimes you no longer want the user account to be used, but you don't
necessarily want it to be deleted.
Maybe it's a user account for doing migrations.
Maybe it's a user account for doing preventive maintenance, something like
that.
And so one of the things you can do is you can come in here and you can actually lock
the user account and then later you can come back and unlock the user account.
And so these are just some of the options that are available to you with the user
profiles that you may not have seen before.
And just again, one of those random things to think about whether or not you use them
very often.
So with that, let us clear the screen again and I will show you how to actually
go about deleting users.
And so from here, all we have to do is we're going to delete the TEM user.
And so we look at, take a look at this, and we're currently logged in as Bob at
server.
And so what we're going to do is we're going to delete the TEM user account.
All we do is DEL user and then whoever it is.
TEM, sudo del user TEM.
Then we're going to hit enter, removing TEM, warning group 10,
TEM has no more members, done.
So basically now the TEM user account has been deleted.
But I want to show you something here.
So let me do the pwd command to show us where we're at.
I'm going to change directory.
I'm going to go up to the home directory and then I'll do lsl and list the
directories that are still up in the home directory.
And what we'll notice is we still have Bob, which is us.
We still have Ralph, a user account we haven't dealt with today.
But the TEM folder is still there.
You still have that TEM profile folder there.
And so we are going to want to delete that TEM profile folder.
So what we can do then is we can use the sudo rm-rf command.
So basically with the sudo and remove, this is the command to remove a directory.
And then we do hyphen rf.
And so why we're going to do hyphen rf is because the directory actually has stuff
in it.
So when Linux creates a profile directory it will then populate that profile
directory with different files that are required for a profile.
So if you simply do the rm command without the extra arguments it'll fail out because
it's not an empty folder.
So we use hyphen rf and this will go through and it will remove the folder and
everything in it.
And then from here what we're going to do is the path.
So it's going to be home and then it's going to be TEM.
So again it's important to be thinking about, especially whenever you do
something like a remove command, is make sure you put in the exact path
that you're going for.
Not time actually, not time.
So here again so from the root directory the home folder in the root directory and
then we want to delete the TEM folder in the home folder.
So wherever you're at you can do that.
And then if you press enter it's now done.
We do ls hyphen l.
We can see that we now have the Bob folder and we have the Ralph folder.
So TEM is now entirely gone.
And that's the basic idea about how to add users, how to change passwords,
how to change users profiles, understanding the password, the
p-a-s-s-w-d file a little bit, how to delete a user, and then how to
delete the profile folder for the user once they've been removed.
So again overall relatively simple.
The main thing that you're going to run into is in the Windows world you can do a
whole bunch more.
And so one of the big problems people run into is they think about Linux as if
they're dealing with Windows and then they basically try to make things more
complicated than they actually are.
And so that's really all there is to the basic user administration in Linux.
So there you go.
Now to be clear, it is Linux.
It is Linux.
So there's 20,000 more things you can do.
So many arguments.
So many options.
So much to be polite idiocy that you can do if you really want to get into it.
So if you're interested about the different things that you can do with user
accounts, you can go and you can take a look.
One of the things that I would warn you about, again in the real world of Linux,
is really ask yourself if you want to be creating Linux accounts from the command
line or do you want to use some other type of software in order to create user
accounts.
Again there's something called Samba.
Samba is basically Linux's version of an Active Directory server.
And so one of the things that you may be thinking about is like, oh cool,
I'm going to create all these user accounts.
But remember, you're creating these directly in the Linux operating system.
And one of the questions to really ask yourself is, is that really what you want
to do?
Or do you want to add an additional piece of software, pieces of software,
something like Samba or some kind of other user account software, and actually run
your user accounts through that additional software?
I would argue that's probably what you're going to do at the end of the day.
The idea being is those additional layers of software, when you add a user account
there, they may add user account to the password file in Linux, but they'll also
do 20 other different tasks.
You create a user account in Samba or something else, and not only does it
create a user account, but it also creates an email account.
It also does this, it does this, it does this, it does this, it does this,
it does this, and so that is a more effective way of dealing with user
accounts in a Linux infrastructure than simply adding users at the command line.
But this can be very useful, again, from a security standpoint, creating user
accounts that can only do specific things within the Linux operating system.
That can be valuable.
Or if you're playing around and doing other things, possibly if you create an
FTP server.
So let's say you want users to be able to upload to your Linux server for whatever
reason, so that you create an FTP server.
In that situation, you may create users at the command line for all of your different
FTP users.
Basically, when they log in, they will then get dumped to wherever the profile
tells them to get dumped.
That's something that you might do with the command line, creating users,
deleting users.
But generally, I would not be creating a lot of user accounts, again, from that
infrastructure type standpoint, just from the command line.
So that's just something to keep in mind.
But really, that's all there is to it.
Again, you've got add user, you've got the password, passwd command.
So with that command, you can change your own password.
Or again, if you're logged in as the root, you could passwords for other users.
The etc slash password, p-a-s-s-w-d file, that contains the information for all your
user accounts.
So you can go there, see all the user accounts that are on the system.
You can see all of that additional information.
Again, I would say, really think about writing notes for, or comments for why
you're creating specific user accounts.
That can be useful when you go back to try to clean up a system.
Again, imagine a Linux system, for whatever reason, you're creating users
at the command line.
When you create five or six users, it's no big deal.
It's very easy to keep track of.
But you should think about what happens when you create 50 users?
What happens when you create 200 users?
What happens when it's three or four years from now, and you're going back and you're
looking to do maintenance and just get rid of old user accounts by simply having
little notes to say why the hell a user account existed.
That can be a very useful thing.
Again, I show you the chfn command that allows you to change the profile
information if that's something that you want to do.
I showed you that usermod command.
We didn't actually use the usermod command, but that's where you can do
things like you can lock a user account if you want to.
Again, that might be very valuable.
Show you how to delete a user.
And then again, remember, just because you delete the user account doesn't mean the
profile folder has been deleted.
And again, from a preventive maintenance standpoint, I would highly argue to delete
those profile folders or you can just get a whole big old mess of profile folders
and you can run into some issues.
So those are some things to think about when adding and deleting users and being
able to manage users on a Linux system.
As always, I enjoyed doing this video and look forward to seeing you in the next one.