Managing Users in Linux: A DevOps Guide ๐Ÿง

Tasneem AfridaTasneem Afrida
3 min read

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! ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

0
Subscribe to my newsletter

Read articles from Tasneem Afrida directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tasneem Afrida
Tasneem Afrida