Thursday 25 August 2011

Creating an User

Syntax :-


[roort@localhost~]# useradd <username>

or

[roort@localhost~]# useradd <option> <argument> <username>

Options:

-u -- UID                                                        -c -- comment

-g -- Primary Group Name or GID                  -d -- Home directory

-o -- Override                                                 -s -- Shell

-G -- Secondary Group

Example :- Creating a user ravi with defalut options

[root@test119 ~]# useradd ravi

To check if the  user has been created

[root@test119 ~]# tail -5 /etc/passwd

gdm:x:42:42::/var/lib/gdm:/sbin/nologin
Ganesh:x:500:500:Ganesh Tulagapu:/home/Ganesh:/bin/bash
ram:x:501:501:ramakrishna:/home/ram:/bin/bash
admin:x:503:503::/home/admin:/bin/sh
ravi:x:504:505::/home/ravi:/bin/sh



Example :- Creating a user ali whose user id (UID) is 2001


[root@test119 ~]# useradd -u 2001 ali

To check if the user has been created

[root@test119 ~]# tail -5 /etc/passwd

Ganesh:x:500:500:Ganesh Tulagapu:/home/Ganesh:/bin/bash
ram:x:501:501:ramakrishna:/home/ram:/bin/bash
admin:x:503:503::/home/admin:/bin/sh
ravi:x:504:505::/home/ravi:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh


Example :- Creating a user tom with a comment 'Manager'


[root@test119 ~]# useradd -c Manager tom


To check if the user has been created

[root@test119 ~]# tail -5 /etc/passwd

ram:x:501:501:ramakrishna:/home/ram:/bin/bash
admin:x:503:503::/home/admin:/bin/sh
ravi:x:504:505::/home/ravi:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
tom:x:2002:2002:Manager:/home/tom:/bin/sh

Example :- Creating a user anu whose home directory is inside /'salesdept'

Note: Before creating a user in salesdept, you should create a directory as /salesdept

[root@test119 ~]# useradd -d /salesdept/anu anu

To check if the user has been created

 [root@test119 ~]# tail -5 /etc/passwd

admin:x:503:503::/home/admin:/bin/sh
ravi:x:504:505::/home/ravi:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
tom:x:2002:2002:Manager:/home/tom:/bin/sh
anu:x:2003:2003::/salesdept/anu:/bin/sh

Example :- Creating a user Jack whose shell is 'c shell'

[root@test119 ~]# useradd -s /bin/csh Jack


To check if user has been created with 'c shell'


[root@test119 ~]# tail -5 /etc/passwd

ravi:x:504:505::/home/ravi:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
tom:x:2002:2002:Manager:/home/tom:/bin/sh
anu:x:2003:2003::/salesdept/anu:/bin/sh
Jack:x:2004:2004::/home/Jack:/bin/csh


Example :- Change the login name of user tom to jill


[root@test119 ~]# usermod -l jill tom

To check if the user has been Modified

[root@test119 ~]# tail -5 /etc/passwd

ravi:x:504:505::/home/ravi:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
anu:x:2003:2003::/salesdept/anu:/bin/sh
Jack:x:2004:2004::/home/Jack:/bin/csh
jill:x:2002:2002:Manager:/home/tom:/bin/sh


To delete a user

Syntax :- 

[root@localhost~]# userdel <option> <username>


Options:

-r -- Recursively (along with the home directory and mailbox)

Example :- Deleting the user ravi

[root@test119 ~]# userdel ravi

To check if the user has been deleted

ram:x:501:501:ramakrishna:/home/ram:/bin/bash
admin:x:503:503::/home/admin:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
anu:x:2003:2003::/salesdept/anu:/bin/sh
Jack:x:2004:2004::/home/Jack:/bin/csh
jill:x:2002:2002:Manager:/home/tom:/bin/sh

[root@test119 ~]# ls /home/
admin  ali  Ganesh  Jack  lost+found  ram  rama  ravi  tera  tom


Example :- Deleting the user Jack along his home directory and mail box
[root@test119 ~]# userdel -r Jack


To check if the user has been deleted

[root@test119 ~]# tail -6 /etc/passwd

Ganesh:x:500:500:Ganesh Tulagapu:/home/Ganesh:/bin/bash
ram:x:501:501:ramakrishna:/home/ram:/bin/bash
admin:x:503:503::/home/admin:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
anu:x:2003:2003::/salesdept/anu:/bin/sh
jill:x:2002:2002:Manager:/home/tom:/bin/sh

[root@test119 ~]# ls /home/
admin  ali  Ganesh  lost+found  ram  rama  ravi  tera  tom

To view the details of a user from all database files

Example:- To view the details of a user anu

[root@test119 ~]# grep anu /etc/passwd /etc/shadow
/etc/passwd:anu:x:2003:2003::/salesdept/anu:/bin/sh
/etc/shadow:anu:!!:15211:0:99999:7:::


To view the UID and GID of a user

Example:- To view the details of a user Anu

[root@test119 ~]# id anu
uid=2003(anu) gid=2003(anu) groups=2003(anu)


To Change the Password Parameters

Syntax:-

[root@localhost~]# chage <username>

Example:- To change the Password Parameters for the User Jill

[root@test119 ~]# chage jill

Changing the aging information for jill
Enter the new value, or press ENTER for the default

        Minimum Password Age [0]: 1
        Maximum Password Age [99999]: 10
        Last Password Change (YYYY-MM-DD) [2011-08-25]:
        Password Expiration Warning [7]: 4
        Password Inactive [-1]:
        Account Expiration Date (YYYY-MM-DD) [1969-12-31]:


To check do the following steps:

1. Log off Root
2. Log in as Jill
3. Try changing the Password
4. Log off as Jill
5. Log in as Root
6. Change the system date to two days ahead
7. Log off as Root
8. Login as Jill
9. Try changing the Password

0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews