Wednesday 3 December 2014

Linux User Management

Users:

All users on a system are identified by a username and a userid. The username is something that users would normally refer to, but as far as the operating system is concerned this is referred to using the userid (or uid). The username is typically a user friendly string, such as your name, whereas the userid is a number.

Types of Users:

There are three basic types of Linux user accounts:
• administrative (root) user (supper user)
• regular users
• Service users


Administrative (root) user:
• The Linux administrative root account is automatically created when you install Linux.
• It has administrative privileges for all services on Linux Operating System. 
• The root account is also known as super user.
• The root users home directory is /root

Regular Users:
• Regular users have the necessary privileges to perform standard tasks on a Linux computer such
as running databases, and Web browsers.
• They can store files in their own home directories “/home/username”
• Since regular users do not normally have administrative privileges, they cannot accidentally
delete critical operating system configuration files.

Service Users:
• Services such as Apache, mail, games, and printing, Fax etc have their own individual
service accounts.
• These accounts exist to allow each of these services to interact with your computer.

User Identification Number (UID):

• Each user on a Red Hat Enterprise Linux system is assigned a unique user identification
number, also known as a UID.
• UIDs below 500 are reserved for system users such as the root user and service users.
• The root user has an id of ‘0’, which has a special meaning. The root user has full
permissions to do anything on the system.

User Group:

• A user group is a group of one or more users.
• A user can be a member of more than one group.
• In Red Hat Enterprise Linux, when a user is added, a private user group (primary group) is created meaning that a user group of the same name is created and that the new user is the sole user in that group.
• A user can have only one Primary Group.
• When a User is created home directory “/home/username” is create by default.
• When any user is created in Linux it affects 4 files
 /etc/passwd
 /etc/group
 /etc/shadow
 /etc/gshadow

/etc/passwd:

• Information about any user stored in a separate file “/etc/passwd”.
• If you explore this file you will see entries like.
 # cat /etc/passwd

/etc/shadow:
• This file contains encrypted password of users.

Creating User:

You can create a user by useradd command
# useradd <username>

Options:
 -u (for specific UID)
 -g (for specific Primary group)
 -d (home Directory)
 -c (comment)
 -G (for Secondary group)

 # useradd applmgr –u 700 -d /oradata/applmgr -c manager -g sales -G market

In above command we have create a user with name applmgr 
We assigned user specific UID (user ID) 700
We assigned user specific home directory /oradata/applmgr
We have commented user as manager  you can comment any thing like designation of user etc.
We have assigned user a specific existing group named slaes means applmgr users primary group is sales.
We have assigned users primary group market.

User Password:
You can assign password for a user by using passwd command.
• This command is used for assigning or changing user password.
# passwd <usrename>
# passwd applmgr

User Login:
• To login user we use “su” switch user.
 # su - <username>
 # su - applmgr

Changing user information's:

for changing user information eg: primary, secondary group etc we user usermod command.
• This Linux command is very powerful to change the user information like group, comment etc.
Options:
-l (to change login name)
 # usermod -l <newname> <oldname>
 # usermod –l oracle applmgr


-L (to lock password)
 # usermod -L oracle
 -U (to unlock password)
 # usermod -U oracle

Delete User:
You can delete user by using userdel command
• By using this command we can delete user.
# userdel <username>
# userdel applmgr

• For deleting user with users  home directory and mail box we use “-r” option.
# userdel -r <username>
# userdel -r applmgr
It will delete user as well as users home directory.

Group Administration:

• Group is a collection of users with same permission.
• There are two types of groups primary and secondary 

Group files:
The information about the group are stored in
/etc/group
/etc/gshadow

/etc/group:

This file contains information about group

/etc/gshadow:

This file contains information's like group password, admin name etc


Adding Group:

You can add group by using groupadd command
This command is used to add a group.
# groupadd <groupname>
# groupadd dba

Create group with group id (GID) 600.
# groupadd –g 600 dba

Change Group Informations:

You can use groupmod command to change groups information's.
• This command is used to change the info. Of group.
• We can change name, GID etc.
#groupmod <groupname>
Options:

-g
(for changing GID)
# groupmod dba -g 700

-n (for changing name)
# groupmod <oldgroup> -n <newgroup>
# groupmod dba -n mba

Delete Group:

groupdel
• This command is used to delete Group.
• Group cant be deleted if it has a primary member.
• So first delete user then delete group.
# groupdel <groupname>
# groupdel dba

gpasswd:

• This command is very useful in group administration.

Options:
-M (add multiple users to group)
-A (add as admin to group)
-a (add a user to group)
-d (delete user from group)

Adding multipule users to group

# gpasswd -M a1, a2, a3 dba 
Where a1, a2, a3 are users and dba is a group.

Delete user from a group
# gpasswd –d a1 dba

Add user as a admin to group
# gpasswd -A a2 dba

Add a single user to group

No comments:

Post a Comment

Ask your Questions....