πŸš€ DevOps 1.0: Linux Users & Groups Simplified! πŸ’»πŸ‘₯

Master the Art of User and Group Management in Linux! πŸŽ―πŸ”‘

Β·

5 min read

πŸš€ DevOps 1.0: Linux Users & Groups Simplified! πŸ’»πŸ‘₯

Prerequisites:

  1. Basic familiarity with the Linux operating system.

  2. Understanding of command-line interface (CLI) and basic shell commands.

πŸ‘₯πŸ”‘ User and Group in Linux: A Brief Overview -

In Linux, users and groups play essential roles in system administration and security.

πŸ‘€ User: A user represents an individual or entity interacting with the system. Each user has a unique username and associated attributes, such as a user ID (UID) and a home directory. Users are granted specific permissions and can execute various operations on the system.

πŸ‘₯ Group: A group is a collection of users with common permissions or administrative purposes. Group membership allows users to share files, directories, and permissions, simplifying access management. Each group has a group ID (GID) and is associated with certain privileges and ownership settings.

πŸ”’ Effective user and group management ensures proper security, resource allocation, and collaboration within a Linux environment. Understanding these concepts empowers administrators to control access, maintain system integrity, and streamline workflows efficiently.

Remember, mastering user and group management is crucial for maintaining a secure and well-organized Linux system. πŸš€πŸ§

πŸ”‘ Key Insights on User Management: Linux Edition! πŸ’‘πŸ‘₯

Here are some crucial points to know about managing users in Linux: πŸ“Œ

  • Users and groups are used to control access to files and resources.

  • Users log in to the system by supplying their username and password.

  • Every file on the system is owned by a user and associated with a group.

  • Every process has an owner and group affiliation, and can only access the resources its owner or group can access.

  • Every user of the system is assigned a unique user ID number ( the UID).

  • Users name and UID are stored in /etc/passwd.

  • The user's password is stored in /etc/shadow in encrypted form.

  • Users are assigned a home directory and a program that is run when they log in (Usually a Shell).

  • Users cannot read, write or execute each other's files without permission.

    πŸ”’πŸ‘€ Types of Users: Exploring User Roles in Linux! πŸš€πŸ‘₯

  • Regular User: πŸ™Žβ€β™‚οΈπŸ™Žβ€β™€οΈ Regular users, also known as standard users, are the most common type of users. They have limited system privileges and typically interact with the system to perform day-to-day tasks and run applications.

  • Root User (Superuser): πŸ§‘β€πŸ’»πŸ”‘ The root user, also called the superuser, holds the highest level of administrative privileges. This user has unrestricted access to all system resources and can make critical changes to the system. However, it is important to use the root account cautiously to avoid accidental damage.

  • Service Account: πŸ€–πŸ‘₯ Service accounts are used to run background services, daemons, or automated processes. They are created specifically for running specific services or applications and often have limited shell access or no login capabilities.

TYPEEXAMPLEUSER ID (UID)GROUP ID (GID)HOME DddIRSHELL
ROOTroot00/root/bin/bash
REGULARsaswat, vagrant1000 to 600001000 to 60000/home/username/bin/bash
SERVICEftp, ssh, apache1 to 9991 to 999/var/ftp etc/sbin/nologin

πŸ’»πŸ”§ Linux User & Group Management: Essential Commands! πŸ› οΈπŸ‘₯

  • cat /etc/passwd - the contents of the /etc/passwd file. This file is a system database that stores essential information about user accounts on the system. Below are all the system users -

  • head -1 /etc/passwd - Displays the top user.

    The above line has 7 columns separated by :

    1. Username

    2. Link to the shadow file. (Shadow file will hold the password encrypted)

    3. Root ID - It is user ID. 0 for root.

    4. Group ID - It is group ID. 0 for root.

    5. Comment

    6. Home dir of the root user.

    7. Login Shell

  • grep vagrant /etc/passwd - Command to search for any user ID in /etc/passwd file. E.g. Search command for vagrant user.

  • cat /etc/group - Command to get all the groups.

NOTE - The is similarity in group and user naming and display.

Search for vargrant in user and group using the grep command given below to see the similarity.

grep vagrant /etc/passwd
grep vargrant /etc/group
  • id vagrant- It gives information about the user.

  • useradd aws- Command to add user. E.g aws user gets add.

      useradd ansible
      useradd jenkins
      useradd aws
    

    To check if users is been added just check the /etc/passwd file.

    tail -3 /etc/passwd

    NOTE - When a user gets created then a group is also created.

  • groupadd devops - Creates a group named devops.

  • usermod -aG devops ansible - It adds ansible user to devops group.

    Above picture you can see ansible is present in devops group.

  • grep devops /etc/group - It search for the devops group from /etc/group file.

    Above you can see ansible is present in the devops group.

    Another way adding of adding user into the group is by directly editing the /etc/passwd file using the command vim /etc/group.

πŸ”’πŸ’» Setting User Password: Securing User Accounts in Linux! πŸ’‘πŸ”

Execute the below command in root user -

passwd ansible - It will set the passwd for the user ansible.

NOTE - To reset the passwd it can all be done in root user

πŸš€πŸ‘₯ Switching UsersπŸ’»πŸ”„:

su - ansible - To switch to ansible user. It will ask for password depending upon the user.

NOTE - If your switching from root user then the password is not required. Password is required if your switching from one regular user to another regular user.

Type exit to logout from the current user.

πŸ› οΈπŸ”§ Some More Handy Linux Commands:

  • last - It shows the users who logged into the system.

  • who and whoami - It will show current login user.

  • lsof -u username - It will list all the files opened by the user.

  • userdel -r aws - It will delete the user with its home directory.

  • groupdel devops - To delete group.

πŸ“šπŸŒŸ Hope you found this article insightful and enjoyed exploring new concepts! Happy Learning and Upskilling! πŸŽ‰πŸ“–πŸ’‘

"DevOps is not a goal, but a never-ending process of continual improvement." - Jez Humble, Co-author of "Continuous Delivery" πŸŒŸπŸ”§

Did you find this article valuable?

Support Chronicles of Tech πŸ“šπŸ’» by becoming a sponsor. Any amount is appreciated!

Β