Managing 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:~$
Modifying the User Account
usermod (Modify Existing User Account) Now, let’s change John’s username to john_doe and update his home directory:
Deleting the User Account
deluser (Delete User Account) Finally, let’s delete the john_doe user account:…
No comments yet. Add the first comment to start the discussion.