Creating Linux Users is (TOO?) Easy!

Shawn Powers
5 Feb 202210:32

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

00:00

💻 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.

05:01

🔧 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.

10:02

🛠 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

A system administrator is responsible for managing and maintaining computer systems, particularly servers and networks. In the video, the speaker jokes about the role being 'quite boring,' but then demonstrates how tasks such as creating and managing users are important responsibilities for administrators.

💡User Creation

User creation refers to the process of setting up a new account on a Linux system, allowing a person to log in and access system resources. In the video, the speaker shows how to create a user named 'Susie' using the 'useradd' command, including steps to assign her a home directory and add her to administrative groups.

💡Home Directory

The home directory is a dedicated folder where a user's files are stored on a system. When creating a user like 'Susie,' the video emphasizes specifying and creating her home directory using the '-d' and '-m' flags to ensure proper setup and permissions for the new user.

💡Supplementary Groups

Supplementary groups are additional groups a user belongs to, which grant access to specific system resources or permissions. The speaker adds 'Susie' to the 'sudo' and 'adm' groups, allowing her to perform administrative tasks on the system. This is done using the '-G' flag in the 'useradd' command.

💡Command Line Tools

Command line tools refer to programs that are run in the terminal, often without a graphical user interface. The video highlights how these tools, like 'useradd' and 'usermod,' simplify user management on Linux systems, as opposed to manually editing system files such as '/etc/passwd.'

💡Sudo

Sudo is a Linux command that allows a permitted user to execute a command as the superuser or another user with elevated privileges. In the video, the speaker uses 'sudo' to perform administrative tasks like creating users and modifying groups, which require root access.

💡Password File (/etc/passwd)

The '/etc/passwd' file is a key Linux system file that stores information about user accounts, including usernames and user IDs. The speaker warns against manually editing this file and instead encourages using command line tools like 'useradd' to manage users, as mistakes in this file can cause system-wide login issues.

💡Usermod

Usermod is a command line tool used to modify user account properties after the account has been created. In the video, the speaker uses 'usermod' to append 'Susie' to additional groups, explaining how using '-aG' ensures that she keeps her existing group memberships while being added to new ones like 'cool people.'

💡Skeleton Directory (/etc/skel)

The skeleton directory ('/etc/skel') contains template files that are copied into a new user's home directory when the account is created. The speaker demonstrates how to pre-populate 'Susie's' home folder with a file from the skeleton directory, ensuring that newly created users start with specific files or configurations.

💡Password Assignment

Password assignment refers to setting or changing a user's password so they can log in. The speaker uses the 'passwd' command to assign 'Susie' a password after creating her account, emphasizing that newly created users do not automatically have a password, so this step is necessary for them to access the system.

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

play00:00

i'm so sorry for the video clip you're

play00:02

about to watch

play00:07

being a system administrator is really

play00:09

quite boring

play00:11

i know

play00:14

[Music]

play00:15

[Applause]

play00:18

oh

play00:19

why am i here well i was i was lonely so

play00:22

i

play00:23

yeah but it's just me

play00:25

so we're the same well i know i mean

play00:27

it's

play00:30

user delete

play00:33

uh let's see what can i do and oh i know

play00:36

user and

play00:41

so

play00:45

okay i'd like to say that i'm never

play00:46

going to do something like that again

play00:47

but that's probably a lie that was kind

play00:49

of fun so anyway what i do want to cover

play00:50

though is creating and deleting and

play00:53

modifying users on your linux system now

play00:56

if you've been watching videos along

play00:57

this series with me uh you'll know that

play01:00

you can actually do this by hand by

play01:02

editing the password file like manually

play01:05

and i'll put a link to the video i think

play01:07

over here is where the the link will be

play01:09

so that if you want to watch that how

play01:10

you can do it manually you can but there

play01:12

are tools on the command line and that's

play01:15

a much much easier way to manage local

play01:18

users and to quote the mandalorian

play01:20

this is the way you don't want to do it

play01:22

manually because it's too easy to make a

play01:24

typo or forget what you're doing or get

play01:26

permissions wrong on a newly created

play01:28

home directory just use the tools

play01:30

especially since they're super easy to

play01:32

use

play01:33

so rather than show a slide with the

play01:35

different tools on it i'm just going to

play01:37

directly show you how to

play01:39

add and delete users so the first thing

play01:41

we're going to do is look at the user

play01:43

add program so i'm going to do user

play01:44

add-h and i'm going to pipe that through

play01:48

the head command and if you're not

play01:50

familiar with the head command we

play01:51

learned this in another video in this

play01:53

series and i don't know i guess maybe

play01:54

you should watch this series it's kind

play01:55

of a fun series it's quick it's easy and

play01:58

there's some cool little nuggets like

play01:59

how to use the head command anyway we do

play02:01

this and we're going to see the top of

play02:03

the command like flags the help screen

play02:05

and there's a couple that i want to

play02:06

point out now you can modify lots of

play02:08

things about a user but by default it's

play02:10

going to do a lot of this stuff anyway

play02:11

the ones that i want to focus on are we

play02:13

can specify the home directory like

play02:16

where the user's home uh files and where

play02:18

all their directory or where their files

play02:20

in the directory are stored so we're

play02:21

going to specify that

play02:22

you can also specify supplementary

play02:25

groups that go along with the main group

play02:28

that will be created when we create them

play02:30

so supplementary groups are the groups

play02:32

that are not the same as their name so

play02:34

like we're going to create the user

play02:36

susie that will be her main group but we

play02:38

can add her to other groups as well

play02:40

we're going to talk about the scale

play02:41

directory we're going to use a default

play02:42

one but i want to talk about that at the

play02:44

end of this video and then lastly i want

play02:46

to make sure that we do the dash m

play02:48

create the home because that's going to

play02:50

create susie's home folder and it's

play02:52

going to make sure it has the right

play02:54

ownership and permission so susie will

play02:56

be able to actually log in so we have

play02:58

all the stuff right there let's actually

play02:59

do it we're going to say sudo we have to

play03:01

be root in order to create a user so

play03:03

we're going to do sudo user ad

play03:06

dash d and her home folder is going to

play03:08

be home

play03:10

susie and i would probably put it there

play03:11

by default but i really want us to

play03:13

specify where her home folder is going

play03:15

to be so it's going to be right there

play03:17

and then dash lowercase m so it goes

play03:19

through the process of creating that

play03:21

home folder so this would just specify

play03:23

where it was but if we want to actually

play03:25

have it created we need to do the dash m

play03:28

and then dash capital g

play03:30

and i want susie to be an administrator

play03:32

so i want to add her to the

play03:34

supplementary group sudo and adm so i

play03:37

want her to have those groups if i press

play03:40

enter

play03:41

oh i forgot to specify her name so at

play03:44

the last command or the last part of it

play03:45

is susie right we have to say uh user ad

play03:49

to the directory home susie create the

play03:50

directory put the user in the these two

play03:53

groups and then you have to actually

play03:54

tell the command what is her name gonna

play03:56

be i just forgot to type that so anyway

play03:58

suzy and now we've created the user

play04:01

susie we can see that by typing id

play04:03

suzy and sure enough there she is uh

play04:05

she's uid 1002 suzy group id 1002 susie

play04:09

and then the supplementary groups that

play04:11

we added her to of course there's the

play04:13

her main group but then the adm and the

play04:15

pseudo group that we added right up here

play04:18

so that is how susie is now um

play04:21

she has an account on our computer if we

play04:23

look at the home directory we're going

play04:25

to see

play04:26

our two users bob and s powers already

play04:27

were there and now susie has her home

play04:29

directory there as well now i want to

play04:31

show you can also add a group really

play04:34

easily too there's not as many commands

play04:36

there so we're just gonna actually say

play04:38

sudo

play04:39

group add

play04:41

cool people

play04:43

okay so now cool people is there but if

play04:45

we still look at the idea of susie she

play04:48

doesn't belong to that group because we

play04:50

just created it didn't even exist when

play04:52

we created her user so in order to add

play04:54

her to that group we're going to use

play04:57

another command and this one isn't

play04:58

actually spelled out for you to learn in

play05:00

the linux essentials objectives but it's

play05:02

vital for you to know so we're just

play05:04

going to cover it i'm going to say sudo

play05:07

user mod

play05:09

dash h if i want to see the help and the

play05:11

same thing i'm going to pipe this

play05:12

through

play05:13

the head command and i want to show 25

play05:15

lines

play05:16

and what i specifically want to point

play05:18

out here are these two things so dash

play05:21

capital g just like when we're creating

play05:23

a user we can add them to a

play05:25

supplementary group so that's how we're

play05:27

going to add susie to the cool people

play05:29

group however we also have to specify

play05:33

dash a and append it because

play05:35

that will append this group to her list

play05:38

of groups otherwise if we just do

play05:40

capital g and put cool people that will

play05:42

be the only supplementary group she

play05:44

belongs to she will no longer be in the

play05:46

adm and the pseudo group so we have to

play05:48

append

play05:50

to her list of groups that's vitally

play05:51

important that we do both of these and

play05:53

that's really why i wanted to show you

play05:55

the help list so anyway we're gonna do

play05:56

sudo

play05:58

user mod

play05:59

dash g

play06:01

cool people and dash a so it appends and

play06:04

then of course the username who we want

play06:06

to add to that group is susie and now if

play06:08

we do an id of susie

play06:10

oh look at that susie still is in the

play06:11

same groups that she was before

play06:14

but also now she's in the cool people

play06:16

group that we created and added her to

play06:19

after the fact now there are some cool

play06:20

things remember i mentioned the skeleton

play06:22

group well if we look so i'm going to do

play06:24

sudo

play06:25

ls

play06:26

home

play06:27

susie

play06:28

there's nothing in there because susie

play06:30

was created with an empty home directory

play06:33

but what if we wanted to preload

play06:36

somebody's folder with some files well

play06:38

we can do that but we have to do it

play06:40

before we actually create her so let's

play06:43

get rid of susie we're going to say sudo

play06:45

user

play06:46

dell and i want to do dash h so we can

play06:48

see the options here and what we're

play06:50

going to do is we're going to force it

play06:52

so that it removes her files

play06:54

and we want to make sure it removes her

play06:56

home directory and her mail spool she

play06:58

doesn't actually have a mail spool setup

play07:00

but it's going to remove everything

play07:02

about susie if we do r and app so we're

play07:05

just going to say sudo user dell dash rf

play07:09

susie and of course yeah it says there

play07:10

is no mail spool there but if we look in

play07:12

like the home directory now susie's gone

play07:15

if we grep susie uh from the etc

play07:17

password file

play07:19

there's none in there and if we do id of

play07:21

susie it's gonna be like there's no such

play07:23

user okay so what i wanna do is go into

play07:25

a folder called etc

play07:28

scale all right and if we do ls there's

play07:30

no main files in here but what if we

play07:32

were to do sudo

play07:33

um touch

play07:35

cool file for

play07:38

cool people

play07:40

and now inside the scale folder there's

play07:42

a file called cool file for cool people

play07:44

okay and it's just an empty file we just

play07:46

touched it and created an empty file but

play07:47

it's there and now if we type cd if we

play07:50

create a user again the next user we

play07:53

create should have this automatically

play07:55

put into their home folder so let's

play07:57

create susie again from scratch and see

play07:59

if that happens so we're going to say

play08:01

sudo

play08:03

user ad dash d home susie

play08:07

dash m for create it dash g

play08:10

we're going to put her in the sudo group

play08:12

the adm group and the cool people

play08:15

group

play08:16

and then her name of course is going to

play08:17

be susie press enter and now id susie

play08:20

make sure we got it all in place yup

play08:22

she's there it's all working and now if

play08:23

we do sudo ls i have to do sudo because

play08:26

otherwise the s powers user wouldn't

play08:28

have access to susie's home folder but

play08:30

if we do home

play08:31

suzy and look inside her folder look at

play08:34

that cool file for cool people was

play08:36

automatically put in her folder

play08:38

a copy of that etc skeleton folder or

play08:41

etc scale is put in new users so you can

play08:44

pre-populate things for when you create

play08:47

new user accounts now one last thing we

play08:49

have to do is when we create a user it

play08:52

doesn't have a password so we have to

play08:54

assign suzy a password if we want her to

play08:56

actually be able to log in and that's a

play08:58

really simple command it's the same

play08:59

command that you change your own

play09:00

password with right if i was going to

play09:01

change my own password i would say pass

play09:03

swd and it would ask me for my old

play09:05

password and change it twice but if you

play09:07

have root privilege like with sudo you

play09:09

can say p-a-s-s-w-d

play09:11

with the user as an argument so sudo

play09:13

password of susie it's gonna say what is

play09:16

her new password i'll say

play09:17

suzy

play09:19

suzy which is a terrible password don't

play09:20

actually use a person's username as our

play09:22

password but i want to show you that if

play09:24

we now ssh which is a way to connect to

play09:26

a computer uh localhost

play09:30

it's go oh i did the wrong thing okay

play09:32

ssh suzy at localhost so i'm trying to

play09:35

connect to our local machine as susie

play09:38

and i type in the suzy password and now

play09:41

who am i who am i

play09:43

i'm susie and i'm logged in in the susie

play09:46

home folder and there's the cool file

play09:47

for cool people now oddly creating and

play09:50

deleting users is not something you do

play09:52

all that often but if you do have to do

play09:55

it please be sure to use the command

play09:57

line tools rather than trying to

play09:58

manipulate the password and the group

play10:00

and the shadow file and everything by

play10:02

hand because it's just an easy way to

play10:04

make a mistake and create a an error

play10:06

that'll lock possibly everybody out of

play10:08

the system if you screw up the password

play10:10

file even you won't be able to log in

play10:12

right so use those tools that's what

play10:14

they're there for um and remember to

play10:16

learn everything

play10:18

do what you love and most importantly be

play10:21

kind if you have comments please leave

play10:23

them in the comment section below and i

play10:25

will see you in the next video bye

Rate This

5.0 / 5 (0 votes)

Related Tags
LinuxUser ManagementCommand LineSystem AdminAutomationBeginner TutorialTech TipsLinux CommandsUser CreationAdmin Tools