Wednesday, July 17, 2013

Managing Users and Groups in Linux

Managing Users and Groups
While users can be either people or accounts which exist for specific applications to use, groups are logical expressions of organization, combining users together for a common purpose. 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). Usually root has UID 0, system users have UID from 1-499 and normal users with above than 500.

Command line utilities for managing users and groups.
useradd usermod userdel
 Standard utilities for adding, modifying, and deleting user accounts.
groupadd groupmod groupdel
Standard utilities for adding, modifying, and deleting groups.
gpasswd Standard utility for administering the /etc/group configuration file.
pwconv, pwunconv  Utilities that can be used for the conversion of passwords to shadow passwords, or back from shadow passwords to standard passwords.

To create a new user and/or change password
#useradd username
#passwd username

To remove password from user
#passwd -d username
All users are stored in /etc/passwd  file
A new line for juan is created in /etc/passwd:

#cat /etc/passwd
juan:x:501:501::/hom e/juan:/bin/bash
The line has the following characteristics:
It begins with the username juan.
There is an x for shadow passwords.
A UID greater than 499 is created.
A GID greater than 499 is created.
The optional GECOS :: information is left blank, it can be used to provide additional information about the user.
The home directory for juan is set to /home/juan/.
The default shell is set to /bin/bash.
#password are stored in /etc/shadow file
#cat /etc/shadow
A new line for juan is created in /etc/shadow:
juan:!!:14798:0:99999:7:::

#groupadd groupname
#groups are stored in /etc/group file
Enable Autologout

You can configure the system to automatically log out idle users after a fixed period of time:
1. Make sure the screen package is installed
#yum install screen

2. Add the following line at the beginning of the /etc/profile file
#vim /etc/profile
trap "" 1 2 3 15

3. Add the following lines at the end of the /etc/profile file to start a screen session each time
SCREENEXEC="screen"
if [ -w $ (tty) ]; then
trap "exec $ SCREENEXEC" 1 2 3 15
echo -n 'Starting session in 30 seconds'
sleep 30
exec $ SCREENEXEC
fi
Note that each time a new session starts, a message will be displayed and the user will have to
wait 30 seconds

4. Add the following lines to the /etc/screenrc configuration file to close the screen session
after a given period of inactivity:
idle 20 lockscreen
autodetach off

It will take effect ofter next login

No comments:

Post a Comment