Linux User Management
- To list out all the users in Linux, use the awk command with -F option. Here, we are accessing a file and printing only the first column with the help of print $1 and awk.
awk -F':' '{ print $1}' /etc/passwd
2. Using id command, you can get the ID of any username. Every user has an id assigned to it and the user is identified with the help of this id. By default, this id is also the group id of the user.
3. The command to add a user. useradd command adds a new user to the directory. The user is given the ID automatically depending on which category it falls in. The username of the user will be as provided by us in the command.
4. Using passwd command to assign a password to a user. After using this command we have to enter the new password for the user and then the password gets updated to the new password.
Granting sudo Privileges:
If you want to grant administrative (sudo) privileges to a user, add the user to the
sudo
group. You can do this by editing the/etc/sudoers
file or using theusermod
command:-
Changing User Information:
You can use the
usermod
command to modify user information, such as the username, home directory, or shell:sudo usermod -l newusername oldusername # Change username
sudo usermod -d /new/home/directory username # Change home directory
sudo usermod -s /bin/bash username # Change default shell
Deleting a User:
To delete a user, use the
userdel
command:sudo userdel username
-
This command only removes the user. If you want to delete the user's home directory and mail spool, you can use the
-r
option:sudo userdel -r username
Subscribe to my newsletter
Read articles from Amit Parad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Amit Parad
Amit Parad
Experienced Cloud / DevOps Engineer with a passion for automating infrastructure and streamlining software delivery processes. Skilled in AWS, Docker, Kubernetes, CI/CD pipelines, Ansible, Terraform & Jenkins. Proven ability to collaborate with development, operations, and QA teams to ensure efficient and reliable deployments.