LINUX USER GROUP MANAGEMENT
-----------------------------------------------------
Linux users
---------------
Three types of user accounts in Linux operating system they are
1)Root User:The Root User is called as Super User, A Super User can run any command with out any restrictions or privileges,This account is ability to carry out all facets of system administration
including adding accounts,changing user passwords,examining log files,installing software etc,when your are signed in as root the shell prompt displays '#' as the last character if your using terminal
2)System User: The system accounts are needed for the operation of system -specified components like mail accounts and sshd account ,also if we install oracle,it will create a user oracle,these kind of users are called as system user
3)Normal User: These users are created by root user .normal users accounts provide access to the system for users and groups of users ,these users have limited access to critical system files and directories
Create Users
---------------
useradd chaitanya
Assign password to user
--------------------------------
passwd chaitanya
changing password for user chaitanya
new password:chai123
retype new password: chai123
passwd:all authentication tokens updated sucessfully
Create a user with account expiry date
--------------------------------------
useradd -e 2020-07-03 abhiram
passwd abhiram
changing password for user abhiram
new password:abhi123
retype new password:abhi123
passwd:all authentication tokens updated succesfully
user add options:
-u ---->user id
-g------>primary group id
-G------>secondary group id
-d------>home directory
-c------>comment -s shell
-s------>shell
create a user with specific userid
--------------------------------------
useradd- u 504 manasa
craete a user with specific userid and group id
------------------------------------------------------
useradd -u 600 -g 504 saibabu
Add a user to multiple groups
------------------------------------
we can add a user to multiple groups by specifying with group name or group id
useradd -G prod,test pavan
id pavan
uid=601(pavan) gid=601(pavan) groups=601(pavan),3460(prod)3461(test)
useradd -G 3460,3461 vasanth
id ward
uid=602(vasanth) gid=602(vasanth)groups=602(vasanth),3460(prod),3461(test)
Add a user with comments
------------------------
useradd -c"administrator" chaitanya
tail -1 /etc/passwd
chaitanya:x:603:603:administrator:/home/chaitanya:/bin/bash
Add user with home directory
----------------------------
useradd -d /home/mydir chaitanya
tail -1 /etc/passwd
chaitanya:x:604:604::/home/mydir:/bin/bash
Deleting a existing user
------------------------
userdel chaitanya
Delete user even if he is still logged in
----------------------------------------
userdel - f manasa
Delete user along with home directory
--------------------------------------------
userdel -r abhiram
Modify User Properties
-----------------------------
changing the home directory of user
grep chaitu /etc/passwd
chaitu:x:504:504::/home/jones:/bin/bash
usermod -d /home/chaithu chaitu
grep chaitu /etc/passwd
user8:x:604:604::/home/chaithu:/bin/bash
Changing the primary group of a user
---------------------------------------------
usermod -g prod vasanth
Locing and unlocing users
--------------------------------
usermod -L abhiram
usermod -U abhiram
verify in /etc/shadow file it shows exclamation(!) mark at user name when user locked, After unlock it will disappear
-----------------------------------------------------------------------------------------------------------------------
usermod -L abhiram
cat/etc/shadow |grep abhiram
abhiram:!$1$nAgOX9u$GLtQsaMcMBvlPUPgY.0:17143:0:99999:7:::
usermod -U abhiram
cat/etc/shadow |grep abhiram
abhiram:$1$nAgOX9u$GLtQsaMcMBvlPUPgY.0:17143:0:99999:7:::
Changing Login name and password
--------------------------------------------
usermod -l abhiram karthikeya
usermod -p P@ssWord abhiram
View account aging information
---------------------------------------
chage -l bobby
changing password parameters
-------------------------------------
chage bobby
changing the aging information for bobby
enter the new value,or press ENTER for the default
User Attributes
---------------------
User type:Super user
User Name: root
User ID: 0
Group ID:0
Home Directory:/root
Shell:/bin/bash
User type:System user
User Name:ftp,mail,apache etc
User ID: 1 to 499
Group ID:1 to 499
Home Directory:/var/ftp/,var/etc etc
Shell:/sbin/nologin
User type:Normal user
User Name: abhiram,vasanth
User ID: 500 to 600000
Group ID:500 to 600000
Home Directory:/home/username
Shell:/bin/bash
Important Files
-------------------
/etc/passwd : keeps user accounts and passwords information this file holds the majority of information about accounts on the linux system
/etc/shadow : holds the encrypted password of the corresponding user account
LINUX GROUPS
-----------------------
Linux Groups are a mechanism to manage a collection of users ,all linux users have a user id (UID) and group id(GID),Groups can be assigned to the users together for
a common security,privilege and access purpose.files and devices may be granted access based on user id or groupid
Important Files
-------------------
/etc/group : This file contains the group information for each account
/etc/shadow : This file contains secure group account inforamatiom
Options
----------
-M -----> add multiple users
-A------> add group administrator
-a------>add single user to group
-d------>removing user from group
Create Groups
------------------
create a new group
----------------------
groudadd group01
tail -1 /etc/group
group01:x:3461:
Creating a group force with success status
--------------------------------------------------
groupadd -f group02
tail -1 /etc/group
group02:x:3462
Creating group with custom GID
---------------------------------------
groupadd -g 5000 group03
tail -1 /etc/group
group03:x:5000:
Creating System Group
-----------------------------
groupadd -r sysgrp
tail -1 /etc/group
sysgrp:x:403:
Modify Groups
-------------------
changing name of the group
groupmod -n newgroup01 group01
Adding and removing user to a group
------------------------------------
gpasswd -M user8,user7 group03
tail /etc/group |grep group03
group03:x:5000:user8,user7
gpasswd -d user6 group03
tail /etc/group | grep group03
group03:x:5000:user8,user7
Delete a group
--------------------
groupdel newgroup01
Note : Info on linux user group management it may be differ from your environment production,testing,development etc
THANKS FOR VIEWING MY BLOG FOR MORE UPDATES FOLLOW ME