Thursday, March 1, 2012

User administration in Linux

Add remove modify users

Only root can do that(need to login in root)

utilities such as useradd,userdel and usermod

(they are in usr/sbin)

default config files in


useradd -D

by default the user will be


after expiration the user account and the files will not be deleted

inactive period : after this amount of time after expiration everything about the user will be deleted

when creating an user 2 files are modified /etc/shadow and /etc/passwd

in the home directory the user's profile is created

in the user's home directory there are files such as

.bash_logout .bash_profile .bashrc .mozilla .emacs .zshrc

they are all user config files,they start with a (.)

in the /etc/skel directory you will find exactly same files

when creating an user the files from /etc/skel is copied in to the user's home directory

set the password of an user (for username lisa),only root can do that

passwd lisa

/etc/passwd stores info about user accounts

/etc/shadow stores the passwords in encrypted format

cat /etc/passwd

the last line would be

x is for password,it means password is showed in /etc/shadow file

first 507 is kennedy's userid

second 507 is kennedy's group id

however the default group id is 100,but red hat gives every user an user private group,here it's id is 507

:: -> this blank space is for an comment which is absent

to add the comment to a user

useradd -c " comment string" sourav(for user sourav)

/home/kennedy is the default home directory for kennedy

/bin/bash is the default shell for kennedy

to delete an user

the command is userdel

userdel -r kennedy

userdel -r will delete the user with it's home directory and all the files in it's home directory

also the /etc/passwd file entry for kennedy will also be deleted

usermod command can alter existing account features

usermod -c "sougata Kundu" sougata

to create multiple user's password at once

cat > password

useradd kuntal

useradd kunal

useradd kundu

ctrl + z

chpasswd < password

the passwords will be set

to see all the groups

cat /etc/group

here we will see entry such as


the first field is the name of the group

the second field x shows the password is stored in a different file

for groups the passwords are saved in /etc/gshadow

501 is the group identification number

next will be users in the group(currentle there are none)

to add a group

to add a regular group instead of a user private group

groupadd -r experts

that will tell the system that we want this group to have a identification number under 500,over 500 numbers are reserved for user private groups

to add an user to this group

usermod -G experts lisa

we can verify in the /etc/group file that in the expert group(which has an id of 102 so it's not an user private group,now has lisa on this group)

let's add another group

groupadd -r adults

to add lisa in this group

if we use

usermod -G adults lisa

lisa will be in adults group but not in experts group anymore

to keep lisa in both groups

usermod -G experts,adulls lisa

to see if a particular user in which groups

the command is

groups lisa

No comments:

Post a Comment