Managing Users in Linux: A DevOps Guide ๐ง
Linux, being a powerful and versatile operating system, provides robust user management capabilities. In this blog post, we'll explore the fundamentals of user management, the significance of user IDs, and practical commands for user information retrieval. To make it more engaging, we'll create two users and display their names using real-life examples.
Understanding User IDs in Linux ๐
After the installation of the operating system, user IDs (UIDs) play a crucial role in defining user privileges. Here's a quick breakdown:
ID 0: Assigned to the root user, who has superuser privileges.
IDs 1 to 999 (inclusive): Reserved for system users.
IDs 1000 and onwards: Assigned to local users.
Essential Commands for User Information ๐ ๏ธ
1. id
Command ๐
The id
command provides detailed information about a user, including their user ID, group ID, and supplementary group IDs.
$ id
uid=1000(username) gid=1000(username) groups=1000(username)
2. who
Command ๐ค
The who
command displays information about users who are currently logged in.
$ who
username tty1 2023-11-14 09:00 (:0)
guest pts/0 2023-11-14 09:30 (192.168.1.2)
3. getent
Command ๐งญ
The getent
command retrieves entries from databases, including user information from /etc/passwd
.
$ getent passwd username
username:x:1000:1000:Your Name:/home/username:/bin/bash
Understanding User Management in Linux ๐ง
1. View Existing Users ๐ง
To see a list of existing users, use the
cat
command with the/etc/passwd
file:cat /etc/passwd
This will display a list of users along with their information.
2. Create New Users ๐
To create a new user, we use the
useradd
command. Let's create two users, Alice and Bob:sudo useradd -m devuser sudo useradd -m opsuser
The
-m
flag ensures that home directories are created for the users.
3. Set Passwords ๐
Assign passwords to the newly created users using the
passwd
command:sudo passwd devuser sudo passwd opsuser
You will be prompted to enter and confirm a password for each user.
Displaying User Names ๐ฅ
Use the
id
command to display user and group information:id devuser id opsuser
This command provides detailed information about the specified user, including their user ID, group ID, and supplementary groups.
2. Alternative: Who Am I? ๐ค
Another way to display user information is by using the
whoami
command:whoami
This command prints the current username to the terminal.
Conclusion ๐
Linux user management is a fundamental aspect of system administration. Understanding user IDs and using the right commands can enhance security and streamline access control. By creating and displaying users, we've demonstrated the practical application of these concepts.
Now, armed with these insights and commands, you're ready to navigate the Linux user landscape with confidence! ๐ฉโ๐ป๐จโ๐ป
Subscribe to my newsletter
Read articles from Tasneem Afrida directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by