Creating, Modifying, and Deleting User Accounts
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 instructsuseraddto create a home directory for the new user. The home directory will be created under/homewith 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/bashis specified as the login shell, which means that the Bash shell will be launched wheneverjohnlogs 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:
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: Anxcharacter indicates that encrypted…
No comments yet. Add the first comment to start the discussion.