0%

0/1 Lessons

Introduction to Linux Server Operating Systems

• 30min

0 / 3 lessons complete

Linux Server Installation and Lab Setup

• 23min

0 / 6 lessons complete

Working with the Linux Command Line Interface

• 1hr 30min

0 / 12 lessons complete

User and Group Management

• 44min

0 / 7 lessons complete

Linux Storage

• 30min

0 / 6 lessons complete

Linux Administration Basics

• 53min

0 / 8 lessons complete

Linux Networking

• 47min

0 / 8 lessons complete

Course Conclusion

• 5min

0 / 1 lessons complete

Instructions

Q&A (0)

Notes (0)

Resources (0)

Saving Progress...

Resources

There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

In this lesson, we will follow the lifecycle of a user account on a Linux/Unix system from creation, through modification, to deletion. We will also cover how to manage user groups.

Creating a User Account

useradd (Create New User Account) Let's start by creating a new user account named john:

sudo useradd -m -s /bin/bash john

Here is a breakdown of what that command does:

  • useradd: This is the command used to create a new user account.
  • -m: This option instructs useradd to create a home directory for the new user. The home directory will be created under /home with the name of the user, in this case /home/john.
  • -s /bin/bash: This option sets the login shell for the new user. Here, /bin/bash is specified as the login shell, which means that the Bash shell will be launched whenever john logs into the system.
  • john: This is the name of the user account being created.

We can run list the contents of /home and should see the users new home directory:

ll /home/
# drwxr-x---  2 john     john     4096 Oct  3 01:08 john/

Additionally, we can switch to the john user by running the following command:

sudo su john

This will show us that we have switch to the john user:

john@ip-10-0-7-42:/home/iacadmin$

We can exit that user by typing 'exit':

exit

This will show that you have switched back to your other user account (in our labs it is iacadmin):

iacadmin@ip-10-0-7-42:~$ 

Understanding the /etc/passwd File

The /etc/passwd file is a text file that describes user account information. Each line in the file represents a single user account and contains seven fields separated by colons (:). Here's the structure:

username:password:userID:groupID:userInfo:homeDirectory:shell
  • username: The name of the user.
  • password: An x character indicates that encrypted password is stored in /etc/shadow file.
  • userID: The unique user ID (UID).
  • groupID: The primary group ID (GID).
  • userInfo: The user's real name or other information.
  • homeDirectory: The absolute path to the user's home directory.
  • shell: The absolute path to the user's login shell.

Let's view our new user account we just created by using grep to filter for john:

grep "john" /etc/passwd

This command will output information like the following:

john:x:1002:1002::/new/home/dir:/bin/bash

You will notice that the password field simply shows x in the /etc/passwd file's password field indicates that the actual encrypted password is stored in the /etc/shadow file, which is a more secure file accessible only by the root user. This change was made to enhance security, as the /etc/passwd file is readable by all users, whereas the /etc/shadow file has stricter access controls. More on the /etc/shadow file in a future lecture.

Modifying the User Account

usermod (Modify Existing User Account) Now, let’s change John’s username to john_doe and update his home directory:

sudo usermod -l john_doe john  # Changes the username
sudo usermod -d /new/home/dir john_doe  # Changes the home directory

Deleting the User Account

deluser (Delete User Account) Finally, let’s delete the john_doe user account:

sudo deluser --remove-home john_doe

We covered:

  • useradd: Create new user accounts.
  • usermod: Modify existing user accounts and manage group memberships.
  • deluser: Delete user accounts.

See you in the next lesson!

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments