SUDO and SU Commands: Mastering User and Group Management in Linux :B6:
In this blog, we'll cover user management: creating, deleting, changing users, and more.
Which User Are You?
To find out which user you're currently logged in as, use the command:
whoami
How to Add a User
To add a new user, use:
sudo adduser thor
Complete the details like the password for the user. Alternatively, to create a user without filling out details:
sudo useradd thor
Listing All Users
To see all users on the machine, use:
cat /etc/passwd
Passwords are stored in /etc/shadow
in a hashed format.
Setting a User's Password
To set a password for a user:
sudo passwd ironman
Changing a User's Shell
To change the shell for a user:
sudo usermod ironman --shell /bin/bash
SU: Switch User
To switch to the root user:
sudo su -
To switch to another user (you'll need the user's password):
su - ironman
To log out from the current user session:
logout
Sudoers File
This file defines who can have superuser privileges. It's recommended to use visudo
to edit it:
sudo visudo
To save the file, use Ctrl + X
, then Y
.
Deleting a User
To delete a user:
sudo userdel thor
Groups
Creating a Group
To create a new group:
sudo groupadd infinity
Checking Groups
To check if a group has been created:
cat /etc/group
To find out which groups you belong to:
groups
Adding a User to a Group
To add a user to a group:
sudo usermod -aG infinity ironman
-aG
: append to groupinfinity
: group nameironman
: user
To grant superuser permissions to a group, edit the sudoers file:
sudo visudo
Find the %sudo
line, copy it, and replace sudo
with your group name.
Removing a User from a Group
To remove a user from a group:
sudo gpasswd -d thanos infinity
To delete a user:
sudo userdel thanos
Deleting a Group
To delete a group:
sudo groupdel infinity
Conclusion
By following the steps outlined in this blog, you can efficiently manage users and groups on your system using superuser privileges. Whether you're adding new users, setting passwords, switching users, or managing groups, these commands and tips will help you maintain a secure and organized environment. Understanding and utilizing the sudo
and su
commands, along with proper configuration of the sudoers file, ensures that you have the necessary control and flexibility to manage your system effectively.
Note:-B6 is blog post 6 of this series
B1 link :- https://khushalmalik.hashnode.dev/the-rise-of-linux
Make sure you subscribe to Newsletter and Do follow !!!!!!!
SUDO is like Superman for linux , Which allows user to run any kind of command
#Khushal_Malik #Devops #Cloud #LinuxTerminalCommands #LinuxUserManagement #SUDOCommand #SUCommand #LinuxGroups #LinuxTerminalCommands #UserPermissionsInLinux #LinuxSystemAdministration #SudoersFile #LinuxUserRoles #LinuxSecurity#HowToManageUsersInLinux #AddingAndDeletingUsersInLinux #SettingUserPasswordsInLinux #ChangingUserShellInLinux #SwitchingUsersWithSUCommand #EditingTheSudoersFileInLinux #CreatingAndManagingGroupsInLinux #GrantingSuperuserPermissionsInLinux #RemovingUsersFromGroupsInLinux #BestPracticesForLinuxUserManagement
Subscribe to my newsletter
Read articles from Khushal Malik directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Khushal Malik
Khushal Malik
I am an Devops Cloud Eng. with 2 years of experience