Creating Linux Users is (TOO?) Easy!
Summary
TLDRThis video demonstrates how to create, delete, and modify users on a Linux system using command-line tools. The speaker explains the importance of using these tools instead of manually editing files like the password file, as errors could lock everyone out of the system. Through practical examples, the video shows how to add users, set home directories, assign groups, and prepopulate home directories with files. It also covers how to modify user groups and assign passwords, emphasizing the ease and safety of using built-in Linux commands.
Takeaways
- 😀 Being a system administrator can seem boring, but it’s an important role.
- 👤 The video demonstrates how to create, delete, and modify users on a Linux system.
- 🔧 Using the command line is an efficient way to manage users, avoiding manual file edits.
- 🏠 You can specify a user’s home directory with the `-d` flag when adding a user.
- 👥 Supplementary groups can be added with the `-G` flag to assign users to multiple groups.
- 📂 The `-m` flag ensures the creation of a user’s home directory with the correct permissions.
- 🛠 The `useradd` and `usermod` commands are essential for managing user groups and permissions.
- 📝 The video covers how to preload a user’s home directory with default files using the `/etc/skel` folder.
- 🚫 The `userdel` command helps remove a user and their associated files from the system.
- 🔑 Setting a password for a new user is done using the `passwd` command, making sure the user can log in.
Q & A
What is the main purpose of the video?
-The video aims to demonstrate how to create, delete, and modify users on a Linux system using command-line tools.
Why does the presenter recommend using command-line tools instead of manually editing system files?
-The presenter recommends using command-line tools because manually editing system files like the password file can lead to errors, such as permission issues or typos, that might lock users out of the system.
Which command does the presenter use to add a new user in the system?
-The presenter uses the `sudo useradd` command with various options like `-d` for specifying the home directory, `-m` to create the directory, and `-G` to assign supplementary groups.
What is the importance of the `-m` option when creating a user?
-The `-m` option ensures that the user’s home directory is created with the appropriate permissions and ownership when the user is added.
How does the presenter add a user to supplementary groups?
-The presenter uses the `sudo usermod -aG` command to append a user to supplementary groups without removing the user from existing groups.
What is the skeleton directory (`/etc/skel`) used for?
-The skeleton directory (`/etc/skel`) is used to prepopulate a user's home directory with default files and settings when the user is created.
How can you assign a password to a newly created user?
-You can assign a password to a newly created user using the `sudo passwd <username>` command, which prompts you to enter the new password for the user.
What happens if you forget to include the `-a` option when using `usermod` to add a user to a group?
-If the `-a` option is omitted, the user will be removed from all their existing supplementary groups and will only belong to the new group specified, which could unintentionally revoke access to certain privileges.
How can you remove a user and their home directory from the system?
-You can remove a user and their home directory using the `sudo userdel -r <username>` command, where `-r` ensures the user’s home directory and mail spool are also deleted.
Why does the presenter advise against modifying the password file manually?
-Modifying the password file manually can lead to mistakes that might corrupt the file or result in login issues, making it safer to use dedicated command-line tools.
Outlines
💻 Apology and Introduction to Linux User Management
The speaker begins by apologizing for the video and admitting that being a system administrator can be boring. They also humorously mention feeling lonely, leading to the creation of the video. The main topic is user management in Linux, particularly creating, deleting, and modifying users using command line tools instead of manually editing files like the password file. This introduction sets the stage for a tutorial on Linux user management.
🔧 Introduction to Adding a New User in Linux
The speaker explains the basics of using the `useradd` command to create new users on a Linux system. They stress the importance of specifying certain parameters, such as the home directory and supplementary groups, to ensure proper user creation. Using the example of creating a user named 'Susie,' the speaker demonstrates how to assign Susie to specific groups and ensure her home directory is created correctly. They also emphasize the importance of using `-m` to create the home directory and avoid mistakes.
🛠 Modifying User Groups and Commands in Linux
The speaker delves into the `usermod` command, focusing on how to modify existing users by appending them to additional groups without overwriting their current group memberships. The speaker demonstrates how to add Susie to a newly created group called 'cool people' and explains the significance of using the `-a` (append) option when modifying groups. This ensures that users remain part of their original groups while being added to new ones.
📂 Populating User Directories with Default Files
The speaker introduces the 'skeleton directory' (`/etc/skel`), which is used to pre-populate a new user’s home directory with default files. They demonstrate this by creating a file in `/etc/skel` and showing that this file appears automatically in Susie's home directory after her account is created. The tutorial concludes with a command for deleting users (`userdel`) and emphasizes the importance of properly managing user files and permissions.
🔒 Assigning and Changing User Passwords
In this section, the speaker explains how to assign a password to a new user using the `passwd` command. They illustrate this by assigning Susie a password, demonstrating how to log in as Susie using SSH, and verifying that the new user has access to their home directory. The speaker highlights the importance of setting strong passwords and ensuring user account security.
🚫 Safely Deleting Users and Preventing System Errors
The final segment emphasizes the importance of using command line tools for managing users rather than manually editing system files like `/etc/passwd`, which could cause severe issues if handled improperly. The speaker summarizes the key points about user management and closes the video with a reminder to learn, enjoy what you do, and be kind.
Mindmap
Keywords
💡System Administrator
💡User Creation
💡Home Directory
💡Supplementary Groups
💡Command Line Tools
💡Sudo
💡Password File (/etc/passwd)
💡Usermod
💡Skeleton Directory (/etc/skel)
💡Password Assignment
Highlights
Introduction to the video with a humorous apology for the clip.
Overview of being a system administrator, humorously described as boring.
Explanation of how to create, delete, and modify users on a Linux system.
Discussion on manually editing the password file versus using command line tools.
Introduction to the 'useradd' command for adding new users.
Demonstration of using the 'useradd -h' command to display help options.
Description of key flags for the 'useradd' command, including specifying home directories and groups.
Step-by-step guide on creating a user named 'Susie' with specific home directory and permissions.
Explanation of creating and adding a new group called 'cool people' using 'groupadd'.
Highlight of the 'usermod' command to modify existing users and append them to groups.
Discussion on using 'userdel' to remove users and their associated files.
Explanation of the 'skel' directory to prepopulate new user directories with default files.
Demonstration of assigning a password to a new user using the 'passwd' command.
Logging into the newly created user account 'Susie' and verifying setup.
Final advice to use command line tools instead of manually editing system files to avoid errors.
Transcripts
i'm so sorry for the video clip you're
about to watch
being a system administrator is really
quite boring
i know
[Music]
[Applause]
oh
why am i here well i was i was lonely so
i
yeah but it's just me
so we're the same well i know i mean
it's
user delete
uh let's see what can i do and oh i know
user and
so
okay i'd like to say that i'm never
going to do something like that again
but that's probably a lie that was kind
of fun so anyway what i do want to cover
though is creating and deleting and
modifying users on your linux system now
if you've been watching videos along
this series with me uh you'll know that
you can actually do this by hand by
editing the password file like manually
and i'll put a link to the video i think
over here is where the the link will be
so that if you want to watch that how
you can do it manually you can but there
are tools on the command line and that's
a much much easier way to manage local
users and to quote the mandalorian
this is the way you don't want to do it
manually because it's too easy to make a
typo or forget what you're doing or get
permissions wrong on a newly created
home directory just use the tools
especially since they're super easy to
use
so rather than show a slide with the
different tools on it i'm just going to
directly show you how to
add and delete users so the first thing
we're going to do is look at the user
add program so i'm going to do user
add-h and i'm going to pipe that through
the head command and if you're not
familiar with the head command we
learned this in another video in this
series and i don't know i guess maybe
you should watch this series it's kind
of a fun series it's quick it's easy and
there's some cool little nuggets like
how to use the head command anyway we do
this and we're going to see the top of
the command like flags the help screen
and there's a couple that i want to
point out now you can modify lots of
things about a user but by default it's
going to do a lot of this stuff anyway
the ones that i want to focus on are we
can specify the home directory like
where the user's home uh files and where
all their directory or where their files
in the directory are stored so we're
going to specify that
you can also specify supplementary
groups that go along with the main group
that will be created when we create them
so supplementary groups are the groups
that are not the same as their name so
like we're going to create the user
susie that will be her main group but we
can add her to other groups as well
we're going to talk about the scale
directory we're going to use a default
one but i want to talk about that at the
end of this video and then lastly i want
to make sure that we do the dash m
create the home because that's going to
create susie's home folder and it's
going to make sure it has the right
ownership and permission so susie will
be able to actually log in so we have
all the stuff right there let's actually
do it we're going to say sudo we have to
be root in order to create a user so
we're going to do sudo user ad
dash d and her home folder is going to
be home
susie and i would probably put it there
by default but i really want us to
specify where her home folder is going
to be so it's going to be right there
and then dash lowercase m so it goes
through the process of creating that
home folder so this would just specify
where it was but if we want to actually
have it created we need to do the dash m
and then dash capital g
and i want susie to be an administrator
so i want to add her to the
supplementary group sudo and adm so i
want her to have those groups if i press
enter
oh i forgot to specify her name so at
the last command or the last part of it
is susie right we have to say uh user ad
to the directory home susie create the
directory put the user in the these two
groups and then you have to actually
tell the command what is her name gonna
be i just forgot to type that so anyway
suzy and now we've created the user
susie we can see that by typing id
suzy and sure enough there she is uh
she's uid 1002 suzy group id 1002 susie
and then the supplementary groups that
we added her to of course there's the
her main group but then the adm and the
pseudo group that we added right up here
so that is how susie is now um
she has an account on our computer if we
look at the home directory we're going
to see
our two users bob and s powers already
were there and now susie has her home
directory there as well now i want to
show you can also add a group really
easily too there's not as many commands
there so we're just gonna actually say
sudo
group add
cool people
okay so now cool people is there but if
we still look at the idea of susie she
doesn't belong to that group because we
just created it didn't even exist when
we created her user so in order to add
her to that group we're going to use
another command and this one isn't
actually spelled out for you to learn in
the linux essentials objectives but it's
vital for you to know so we're just
going to cover it i'm going to say sudo
user mod
dash h if i want to see the help and the
same thing i'm going to pipe this
through
the head command and i want to show 25
lines
and what i specifically want to point
out here are these two things so dash
capital g just like when we're creating
a user we can add them to a
supplementary group so that's how we're
going to add susie to the cool people
group however we also have to specify
dash a and append it because
that will append this group to her list
of groups otherwise if we just do
capital g and put cool people that will
be the only supplementary group she
belongs to she will no longer be in the
adm and the pseudo group so we have to
append
to her list of groups that's vitally
important that we do both of these and
that's really why i wanted to show you
the help list so anyway we're gonna do
sudo
user mod
dash g
cool people and dash a so it appends and
then of course the username who we want
to add to that group is susie and now if
we do an id of susie
oh look at that susie still is in the
same groups that she was before
but also now she's in the cool people
group that we created and added her to
after the fact now there are some cool
things remember i mentioned the skeleton
group well if we look so i'm going to do
sudo
ls
home
susie
there's nothing in there because susie
was created with an empty home directory
but what if we wanted to preload
somebody's folder with some files well
we can do that but we have to do it
before we actually create her so let's
get rid of susie we're going to say sudo
user
dell and i want to do dash h so we can
see the options here and what we're
going to do is we're going to force it
so that it removes her files
and we want to make sure it removes her
home directory and her mail spool she
doesn't actually have a mail spool setup
but it's going to remove everything
about susie if we do r and app so we're
just going to say sudo user dell dash rf
susie and of course yeah it says there
is no mail spool there but if we look in
like the home directory now susie's gone
if we grep susie uh from the etc
password file
there's none in there and if we do id of
susie it's gonna be like there's no such
user okay so what i wanna do is go into
a folder called etc
scale all right and if we do ls there's
no main files in here but what if we
were to do sudo
um touch
cool file for
cool people
and now inside the scale folder there's
a file called cool file for cool people
okay and it's just an empty file we just
touched it and created an empty file but
it's there and now if we type cd if we
create a user again the next user we
create should have this automatically
put into their home folder so let's
create susie again from scratch and see
if that happens so we're going to say
sudo
user ad dash d home susie
dash m for create it dash g
we're going to put her in the sudo group
the adm group and the cool people
group
and then her name of course is going to
be susie press enter and now id susie
make sure we got it all in place yup
she's there it's all working and now if
we do sudo ls i have to do sudo because
otherwise the s powers user wouldn't
have access to susie's home folder but
if we do home
suzy and look inside her folder look at
that cool file for cool people was
automatically put in her folder
a copy of that etc skeleton folder or
etc scale is put in new users so you can
pre-populate things for when you create
new user accounts now one last thing we
have to do is when we create a user it
doesn't have a password so we have to
assign suzy a password if we want her to
actually be able to log in and that's a
really simple command it's the same
command that you change your own
password with right if i was going to
change my own password i would say pass
swd and it would ask me for my old
password and change it twice but if you
have root privilege like with sudo you
can say p-a-s-s-w-d
with the user as an argument so sudo
password of susie it's gonna say what is
her new password i'll say
suzy
suzy which is a terrible password don't
actually use a person's username as our
password but i want to show you that if
we now ssh which is a way to connect to
a computer uh localhost
it's go oh i did the wrong thing okay
ssh suzy at localhost so i'm trying to
connect to our local machine as susie
and i type in the suzy password and now
who am i who am i
i'm susie and i'm logged in in the susie
home folder and there's the cool file
for cool people now oddly creating and
deleting users is not something you do
all that often but if you do have to do
it please be sure to use the command
line tools rather than trying to
manipulate the password and the group
and the shadow file and everything by
hand because it's just an easy way to
make a mistake and create a an error
that'll lock possibly everybody out of
the system if you screw up the password
file even you won't be able to log in
right so use those tools that's what
they're there for um and remember to
learn everything
do what you love and most importantly be
kind if you have comments please leave
them in the comment section below and i
will see you in the next video bye
Ver Más Videos Relacionados
5.0 / 5 (0 votes)