User & Group Management


What three things must you do to manage user accounts?
  1. Create accounts_(useradd)
  2. Modify accounts_(usermod)
  3. Delete accounts_(userdel)
The most basic task is to create an account to represent the user who will be working on the system. Each user must authenticate to Linux with an identity that can be used to control their resource access and consumption. User accounts are stored in the /etc/passwd file. That file should not be edited directly by tools such as Vim. Instead, there is useradd, a user-creation utility that adds an account but also accomplishes additional tasks.

Each user is associated with a unique numerical identification number called a user ID (UID). Likewise, each group is associated with a group ID (GID). A user who creates a file is also the owner and group owner of that file. The file is assigned separate read, write, and execute permissions for the owner, the group, and everyone else. The file owner can be changed only by root, and access permissions can be changed by both the root user and file owner.

Additionally, Red Hat Enterprise Linux supports access control lists (ACLs) for files and directories which allow permissions for specific users outside of the owner to be set.

Reserved User and Group IDs:-
-----------------------------
Red Hat Enterprise Linux reserves user and group IDs below 1000 for system users and groups. By default, the User Manager does not display the system users. Reserved user and group IDs are documented in the setup package. To view the documentation, use this command:

[root@localhost ~]# cat /usr/share/doc/setup*/uidgid

Create a user account:-
-----------------------

[root@localhost ~]# useradd Bharat

Note:- "Bharat" is a user.

Create a user with custom home directory:-
------------------------------------------
[root@localhost ~]# useradd User-2 -m -d /home/king
[root@localhost ~]# ll /home/
total 4
drwx------. 15 abhishek abhishek 4096 May 19  2021 abhishek
drwx------.  3 Bharat   Bharat     78 Mar 12 17:15 Bharat
drwx------.  3 User-2   User-2     78 Mar 12 17:29 king
drwxr-xr-x.  2 root     root        6 Mar 12 17:18 sales

Login to a different user(Normal User):-
----------------------------------------
[root@localhost ~]# whoami 
root
[root@localhost ~]# su User-2
[User-2@localhost root]$ 
[User-2@localhost root]$ whoami 
User-2
[User-2@localhost root]$ 

Note:- "whoami" is used for check the current location. "User-2" is the normal user.

Show the details of Users:-
---------------------------
[root@localhost ~]# tail /etc/passwd

abhishek:x:504:504:abhishek:/home/abhishek:/bin/bash 

The above entry contains a set of seven colon-separated fields, each field has it’s own meaning. Let’s see what are these fields: 
  1. Username: User login name used to login into system. It should be between 1 to 32 characters long. 
  2. Password: User password (or x character) stored in /etc/shadow file in encrypted format. 
  3. User ID (UID): Every user must have a User ID (UID) User Identification Number. By default UID 0 is reserved for root user and UID’s ranging from 1-99 are reserved for other predefined accounts. Further UID’s ranging from 100-999 are reserved for system accounts and groups. 
  4. Group ID (GID): The primary Group ID (GID) Group Identification Number stored in /etc/group file. 
  5. User Info: This field is optional and allow you to define extra information about the user. For example, user full name. This field is filled by ‘finger’ command. 
  6. Home Directory: The absolute location of user’s home directory. 
  7. Shell: The absolute location of a user’s shell i.e. /bin/bash. 
Create a user with specific user id:-
-------------------------------------
[root@localhost ~]# useradd -u 1007 abhi

[root@localhost ~]# tail /etc/passwd
abhi:x:1007:1007::/home/abhi:/bin/bash


Create a user with specific group id:-
-------------------------------------
[root@localhost ~]# useradd -u 1010 -g 1007 avinash

Note:- "Group id must be create before use this command"

[root@localhost ~]# tail /etc/passwd
avinash:x:1010:1007::/home/avinash:/bin/bash

Create a user with User's information:-
---------------------------------------
[root@localhost ~]# useradd -c "Desktop Support Engineer" User-11

[root@localhost ~]# tail /etc/passwd
User-11:x:1011:1011::Desktop Support Engineer/home/User-11:/bin/bash

Change the user's Name:-
------------------------
[root@localhost ~]# usermod -l User-12 User-11

Note:- " User-12 is the new user name & User-11 is the old user name."

No comments:

Post a Comment

Computer Hardware_(A+) & Operating System with Networking

Microprocessor Motherboard About Operating System Create Bootable Pen Drive via Command Map Network Drive File Transfer Protocol in Windows ...