Monday, August 19

User and Group Administration Concept On RHEL / CentOS 5&6

In Command Mode Practice These Steps:-

vim  /etc/passwd : contains user information
vim  /etc/shadow  : contains users password information
vim  /etc/group : contains groups information

cat /etc/passwd : to view total users info
cat /etc/passwd | grep sam  (or) getent passwd sam : to view only sam users information
cat /etc/shadow : to view passwords of all existing users
cat /etc/shadow | grep sam (or) getent shadow sam : to view only sam users password
cat /etc/group : to view all groups information
cat /etc/group | grep hr (or) getent group hr : to view only hr group information.

useradd <option> <username>

-u : TO change uid
syn: useradd -u <uidno> <username>
ex: useradd -u 1000  mahesh

-g : to add an user into a group(with out primary group)
useradd -g <groupname> <username>

ex: useradd -g cyber naveen

-G :to add an user into a group(with primary group)
useradd -G <groupname> < username>

-s :to change shell
useradd -s <shell> <username>
/sbin/nologin: user can't able to login from this pc(he can login from remote pc)
syntax: useradd -s /sbin/nologin admin
/bin/false : user can't login from this pc from remote pc
useradd -s /bin/false <username>
-d : to change home directory of an user
syntax:useradd -d <home dir place> <username>
useradd -d /usr/mahi  mahi

To modify an existing users account


usermod : usermod is the command to change modifications to an exisiting user account.

usermod -u <username> : to change uid of an existing user
usermod -G <groupname> <username> : to add an user into an existing group along with his primary group
usermod -g <groupname> <username> : to add an existing user into an existing group with out his primary group
usermod -d <home directory> <username> : to change an existing users home directory.
usermod -s <shell> <username> : to change shell for an existing user

gpasswd -a  : to add an user into ennumber of groups
syntax: gpasswd -a <username> <groupname>
ex: gpasswd -a  mahesh  hr
here we are adding mahesh  into hr group

gpasswd -d : to remove an user from a group
syntax: gpasswd -d <username> <groupname>
ex: gpasswd -d mahesh  hr
here we are removing mahesh from hr group

gpasswd -M : to add ennumber of existing users into  a group along with primary group.
syntax: gpasswd -M <user1>,<user2>,<user3> <groupname>
ex: gpasswd -M  mahesh,naveen,raju  hr
here we are adding mahesh,naveen,raju  into hr group

userdel -r : to delete an user account
syntax: userdel -r <username>
ex: userdel -r naveen (here we are deleting user naveen)


Group: group is nothing but logical grouping of users :

groupadd : this is the command to add a group
syntax: groupadd <groupname>
ex: groupadd  itdepart

groupdel : groupdel is the command to remove a group.
syntax: groupdel <groupname>
ex: groupdel itdepart (here we are deleting itdepart group).

groupmod : used to modify an existing group.
options:
-n : to change name of a group
syntax: groupmod -n <newname> <oldname>
ex: groupmod -n itdepartment  itdepart

chgrp : chgrp is the command to change group ownership of a file or directory
syntax: chgrp <groupname> <file or dir name>
ex: chgrp itdepartment   /java
here we are changing groupownership of /java to itdepartment  group

chown : chown is the command to change ownership of a file or directory
synax:  chown <username> <file or dir name>
ex: chown mahesh   /java/oops
here we are changing ownership of /java/oops to mahesh

chown -R :to change ownership & groupownership of a file or directory
syntax: chown -R <owner:groupowner> <file or dir>
ex: chown -R mahesh:itdepartment  /java/oops
here we are changing ownership of /java/oops to mahesh & groupownership to itdepartment group

3 comments:

  1. To check the password expiry date of a user :

    $chage -l

    Last password change : Nov 18, 2013
    Password expires : Feb 16, 2014
    Password inactive : never
    Account expires : never
    Minimum number of days between password change : 1
    Maximum number of days between password change : 90
    Number of days of warning before password expires : 7

    ReplyDelete

:: Linux - Legends ::