0% found this document useful (0 votes)
26 views4 pages

3.user Management

The document discusses user account management in Linux. It demonstrates how to use commands like useradd to create users, usermod to modify users, and userdel to delete users. It shows examples of creating users with default settings, custom user IDs, home directories, comments, and shells. It also demonstrates modifying user IDs, home directories, and deleting user accounts along with their home directories.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

3.user Management

The document discusses user account management in Linux. It demonstrates how to use commands like useradd to create users, usermod to modify users, and userdel to delete users. It shows examples of creating users with default settings, custom user IDs, home directories, comments, and shells. It also demonstrates modifying user IDs, home directories, and deleting user accounts along with their home directories.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

23

Module 2: User Management

User Management Commands


useradd To create user account
usermod To modify user account
userdel To delete user account
id To display id of a user
tail -5 To display bottom 5 lines of a file
grep To display a sleeted line in a file

“useradd” Command Options


useradd To create user account with defaults
-u use id (UID)
-d To create user account with specific user home Directory
-g Primary Group Name or GID
-o Override
-G Secondary Group
-c Comment
-s Shell

Creating user “gayatri” with default options

[root@localhost ~]# useradd ramuuser


[root@localhost ~]#
[root@localhost ~]# tail -5 /etc/passwd
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
mkdirsabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
venkat:x:500:500:venkatgv:/home/venkat:/bin/bash -
gcleasai:x:501:501::/home/sai:/bin/bash
gayatri:x:502:502::/home/gayatri:/bin/bash
[root@localhost ~]#

Creating user “raj” with user ID 2000


[root@localhost ~]# useradd -u 2000 raj
[root@localhost ~]#
[root@localhost ~]# tail -5 /etc/passwd
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
venkat:x:500:500:venkatgv:/home/venkat:/bin/bash
sai:x:501:501::/home/sai:/bin/bash
gayatri:x:502:502::/home/gayatri:/bin/bash
raj:x:2000:2000::/home/raj:/bin/bash
[root@localhost ~]#
24

Creating user “sairaj” with comment “itmanager”

[root@localhost ~]# useradd -c itmanager sairaj


[root@localhost ~]# tail -5 /etc/passwd
venkat:x:500:500:venkatgv:/home/venkat:/bin/bash
sai:x:501:501::/home/sai:/bin/bash
gayatri:x:502:502::/home/gayatri:/bin/bash
raj:x:2000:2000::/home/raj:/bin/bash
sairaj:x:2001:2001:itmanager:/home/sairaj:/bin/bash
[root@localhost ~]#

Creating user “aditya” with home directory “itdept”


[root@localhost ~]# mkdir /itdept
[root@localhost ~]#
[root@localhost ~]# useradd -d /itdept/aditya aditya
[root@localhost ~]#
[root@localhost ~]# tail -5 /etc/passwd
sai:x:501:501::/home/sai:/bin/bash
gayatri:x:502:502::/home/gayatri:/bin/bash
raj:x:2000:2000::/home/raj:/bin/bash
sairaj:x:2001:2001:itmanager:/home/sairaj:/bin/bash
aditya:x:2002:2002::/itdept/aditya:/bin/bash
[root@localhost ~]#

Creating user “baba” with home specific shell “c shell”


[root@localhost ~]# useradd -s /bin/csh baba
[root@localhost ~]#
[root@localhost ~]# tail -5 /etc/passwd
gayatri:x:502:502::/home/gayatri:/bin/bash
raj:x:2000:2000::/home/raj:/bin/bash
sairaj:x:2001:2001:itmanager:/home/sairaj:/bin/bash
aditya:x:2002:2002::/itdept/aditya:/bin/bash
baba:x:2003:2003::/home/baba:/bin/csh [root@localhost
~]#

Creating user “ram” with specific UID, Comment, home directory and Shell

[root@localhost ~]# mkdir /sales


[root@localhost ~]#
[root@localhost ~]# useradd -u 786 -c manager -d/sales/ram -s /bin/csh ram
[root@localhost ~]#
25

Assigning Password for “ram” user and Checking Database file


[root@localhost ~]# passwd ram
Changing password for user ram.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#
[root@localhost ~]# tail -5 /etc/shadow
baba:!!:14926:0:99999:7:::
durga:!!:14926:0:99999:7:::
madhu:!!:14926:0:99999:7:::
banu:!!:14926:0:99999:7:::
ram:$1$qscBm1GI$3rvS9FbmmWsCh3CMbEwdH0:14926:0:99999:7:::
[root@localhost ~]#

Modifying User ID for “banu” user from “850 TO 750”

[root@localhost ~]# tail -3 /etc/passwd


madhu:x:950:950:manager:/sales:/bin/csh
banu:x:850:850:manager:/sales:/bin/csh
ram:x:786:786:manager:/sales/ram:/bin/csh
[root@localhost ~]#
[root@localhost ~]# usermod -u 750 banu
[root@localhost ~]#
[root@localhost ~]# tail -3 /etc/passwd
madhu:x:950:950:manager:/sales:/bin/csh
banu:x:750:850:manager:/sales:/bin/csh
ram:x:786:786:manager:/sales/ram:/bin/csh
[root@localhost ~]#

Modifying Home Directory for user “baba” form “/home TO /hwdept”

[root@localhost ~]# mkdir /hwdept


[root@localhost ~]#
[root@localhost ~]# grep baba /etc/passwd
baba:x:2003:2003::/home/baba:/bin/csh [root@localhost ~]#
usermod -d /hwdept/baba baba [root@localhost ~]#
[root@localhost ~]# grep baba /etc/passwd
baba:x:2003:2003::/hwdept/baba:/bin/csh
[root@localhost ~]#
6
Deleting user “venkat” along with “home directory” also

[root@localhost ~]# userdel -r venkat


[root@localhost ~]# ls
/home baba gayatri kumar sai
[root@localhost ~]#

NOTE : This command will delete “user” along with “Home directory”
also

Deleting “sairaj” user account :

[root@localhost ~]# ls /home


baba gayatri kumar sai sairaj venkat
[root@localhost ~]#
[root@localhost ~]# userdel sairaj
[root@localhost ~]#
[root@localhost ~]# ls /home
baba gayatri kumar sai sairaj venkat
[root@localhost ~]#
[root@localhost ~]# rm -r –f sairaj

NOTE : Manually you have to Delete “sairaj” home directory

A user is an entity, in a Linux operating system, that can manipulate files


and perform several other operations. Each user is assigned an ID that is
unique for each user in the operating system

structured my explanation of account administration like this:

What three things must you do to manage user accounts?

 Create accounts
 Modify accounts
 Delete accounts

So, what three commands accomplish these tasks? (As in


my overview on account administration, these commands
are for Red Hat Enterprise Linux and RHEL-like
distributions

You might also like