You are on page 1of 6

K. J.

SOMAIYA INSTITUTE OF ENGINEERING AND INFORMATION TECHNOLOGY, SION, MUMBAI-400022

Experiment No. 6

Aim : Execution of User Management Commands like who, whoami, su, sudo, login, logout, exit,
passwd, useradd/adduser, usermod, userdel, groupadd, groupmod, groupdel, gpasswd, chown, chage,
chgrp, chfn, etc.
Objective : To understand file system management and user management commands in Unix.
Software Required : Terminal of Ubuntu Operating System
Theory :
Unix is a multi-user operating system i.e., it allows multiple users on different computers or terminals to
access a single system. This makes it mandatory to know how to perform effective user management;
how to add, modify, suspend, or delete user accounts, along with granting them the necessary
permissions to do their assigned tasks. For this multi-user design to work properly there needs to be a
method to enforce concurrency control. The functions of the following User Management Commands
are :
1. who :   In Unix, “who” command allows to show or print the number of users who has been logged
into your Unix computer system currently. The main usage of who command in Unix without
command-line parameter is to show the name of the users who are logged in currently.
Syntax : who [options] [filename]

2. whoami : Displays user, group and privileges information for the user who is currently logged on to
the local system. If used without parameters, whoami displays the current domain and user name.
Syntax : whoami

3. su : The Unix command su, which stands for 'substitute user' (originally 'superuser'), is used by a
computer user to execute commands with the privileges of another user account. When executed it
invokes a shell without changing the current working directory or the user environment.
Syntax : su [options] [username [arguments]]

4. sudo : The sudo command allows you to run programs with the security privileges of another user
(by default, as the superuser). It prompts you for your personal password and confirms your request
to execute a command by checking a file, called sudoers, which the system administrator configures.
Syntax : sudo [command]

5. login : login is used when signing onto a system. It can also be used to switch from one user to
another at any time (most modern shells have support for this feature built into them, however). If an
argument is not given, login prompts for the username.
Syntax : login [username]

6. logout : The logout command terminates all processes either with the same controlling terminal as
the present process or with all processes which have this terminal open. Processes that are not
children of the present process are terminated upon access to the terminal.
Syntax : logout
DEPARTMENT OF INFORMATION TECHNOLOGY / CLASS- SY / SEM-IV / SUB-UNIX LAB) / ACADEMIC YEAR-2021-22(EVEN) / VARUN KANBHAT (26)
K. J. SOMAIYA INSTITUTE OF ENGINEERING AND INFORMATION TECHNOLOGY, SION, MUMBAI-400022

7. exit : exit command in Unix is used to exit the shell where it is currently running. It takes one more
parameter as [N] and exits the shell with a return of status N. If n is not provided, then it simply
returns the status of last command that is executed.
Syntax : exit [n]

8. passwd : The passwd command is used to change the password of a user account. A normal user
can run passwd to change their password, and a system administrator (the superuser) can use passwd
to change another user's password, or define how that account's password can be used or changed.
Syntax : passwd [options] [username]

9. useradd : useradd is a command in Unix that is used to add user accounts to your system. It is just a
symbolic link to adduser command in Unix and the difference between both of them is that useradd
is a native binary compiled with system whereas adduser is a Perl script which uses useradd binary
in the background. 
Syntax : useradd [options] name_of_the_user

10. usermod : usermod command or modify user is a command in unix that is used to change the
properties of a user in unix through the command line. After creating a user we have to sometimes
change their attributes like password or login directory etc. so in order to do that we use the usermod
command. 
Syntax : usermod [options] USER

11. userdel : userdel command in Unix system is used to delete a user account and related files. This
command basically modifies the system account files, deleting all the entries which refer to the
username LOGIN. It is a low-level utility for removing the users.
Syntax : userdel [options] LOGIN

12. groupadd : groupadd command creates a new group account using the values specified on the
command line and the default values from the system. The new group will be entered into the system
files as needed.
Syntax : groupadd [options] group_name

13. groupmod : groupmod command in unix is used to modify or change the existing group on unix
system. It can be handled by superuser or root user. Basically, it modifies a group definition on the
system by modifying the right entry in the database of the group. 
Syntax : groupmod [options] GROUP

14. groupdel : groupdel command is used to delete a existing group. It will delete all entry that refers to
the group, modifies the system account files, and it is handled by superuser or root user. 
Syntax : groupdel [options] GROUPNAME

15. gpasswd : The gpasswd command is used to administer /etc/group, and /etc/gshadow. Every group
can have administrators, members and a password. System administrators can use the -A
option to define group administrator(s) and the -M option to define members. They have all rights of
group administrators and members.
Syntax : gpasswd [options] GROUPNAME
DEPARTMENT OF INFORMATION TECHNOLOGY / CLASS- SY / SEM-IV / SUB-UNIX LAB) / ACADEMIC YEAR-2021-22(EVEN) / VARUN KANBHAT (26)
K. J. SOMAIYA INSTITUTE OF ENGINEERING AND INFORMATION TECHNOLOGY, SION, MUMBAI-400022

16. chown : To change owner, change the user and/or group ownership of each given File to a new
Owner. Chown can also change the ownership of a file to match the user/group of an existing
reference file.
Syntax : chown [OPTION]… [OWNER][:[GROUP]] FILE…

17. chage : chage command is used to view and change the user password expiry information. This
command is used when the login is to be provided for a user for limited amount of time or when it is
necessary to change the login password time to time.
Syntax : chage [options] LOGIN

18. chgrp : chgrp command in Unix is used to change the group ownership of a file or directory. All
files in Unix belong to an owner and a group. You can set the owner by using “chown” command,
and the group by the “chgrp” command.
Syntax : chgrp [OPTION]… GROUP FILE…

19. chfn : In Unix, the chfn (change finger) command updates the finger information field in your
/etc/passwd entry. The contents of this field can vary among systems, but this field usually includes
your name, your office and home addresses, and the phone numbers for both.
Syntax : chfn [option] [login]

Conclusion : Here, we learn to execute various User Management commands in the Unix Operating
System like creating a user, deleting an existing user , creating groups, deleting groups, changing their
passwords, etc. and also understand about their functions the various options that are provided by
each command and also learn its usage.
Outcome : Applied Unix commands for system administrative tasks such as file system management
and user management.

Output :
adminit@adminit-OptiPlex-3010:~$ man sudo su
--Man-- next: su(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
^C
adminit@adminit-OptiPlex-3010:~$ adduser varun
adduser: Only root may add a user or group to the system.
adminit@adminit-OptiPlex-3010:~$ id
uid=1000(adminit) gid=1000(adminit)
groups=1000(adminit),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),131(lxd),132(sa
mbashare)
adminit@adminit-OptiPlex-3010:~$ ip
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
where OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila |
DEPARTMENT OF INFORMATION TECHNOLOGY / CLASS- SY / SEM-IV / SUB-UNIX LAB) / ACADEMIC YEAR-2021-22(EVEN) / VARUN KANBHAT (26)
K. J. SOMAIYA INSTITUTE OF ENGINEERING AND INFORMATION TECHNOLOGY, SION, MUMBAI-400022

vrf | sr | nexthop }
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-h[uman-readable] | -iec | -j[son] | -p[retty] |
-f[amily] { inet | inet6 | mpls | bridge | link } |
-4 | -6 | -I | -D | -M | -B | -0 |
-l[oops] { maximum-addr-flush-attempts } | -br[ief] |
-o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
-rc[vbuf] [size] | -n[etns] name | -N[umeric] | -a[ll] |
-c[olor]}

adminit@adminit-OptiPlex-3010:~$ lp
lp: Error - No default destination.
adminit@adminit-OptiPlex-3010:~$ sudo su
[sudo] password for adminit:
root@adminit-OptiPlex-3010:/home/adminit# ^C
root@adminit-OptiPlex-3010:/home/adminit# login
adminit-OptiPlex-3010 login: ^Z^C
root@adminit-OptiPlex-3010:/home/adminit# lad
^Croot@adminit-OptiPlex-3010:/home/adminit# login adminit
Password:
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-41-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
0 updates can be installed immediately.
0 of these updates are security updates.

The list of available updates is more than a week old.


To check for new updates run: sudo apt update
Your Hardware Enablement Stack (HWE) is supported until April 2025.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
adminit@adminit-OptiPlex-3010:~$ sudo su
root@adminit-OptiPlex-3010:/home/adminit# adduser varun

Adding user ` varun ' ...


Adding new group ` varun ' (1001) ...
Adding new user ` varun ' (1001) with group ` varun ' ...
Creating home directory `/home/ varun ' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for varun
Enter the new value, or press ENTER for the default
Full Name []: Varun Kanbhat
Room Number []:
DEPARTMENT OF INFORMATION TECHNOLOGY / CLASS- SY / SEM-IV / SUB-UNIX LAB) / ACADEMIC YEAR-2021-22(EVEN) / VARUN KANBHAT (26)
K. J. SOMAIYA INSTITUTE OF ENGINEERING AND INFORMATION TECHNOLOGY, SION, MUMBAI-400022

Work Phone []:


Home Phone []:
Other []: Varun
Is the information correct? [Y/n] y
root@adminit-OptiPlex-3010:/home/adminit# login varun
Password:
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-41-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
0 updates can be installed immediately.
0 of these updates are security updates.
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Your Hardware Enablement Stack (HWE) is supported until April 2025.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
varun@adminit-OptiPlex-3010:~$ who google
varun@adminit-OptiPlex-3010:~$ who www.google.com
varun@adminit-OptiPlex-3010:~$ who
adminit :0 2022-02-25 09:27 (:0)
varun pts/0 2022-02-25 09:55
varun@adminit-OptiPlex-3010:~$ whoami
varun
varun@adminit-OptiPlex-3010:~$ logout varun
-bash: logout: varun: numeric argument required
root@adminit-OptiPlex-3010:/home/adminit# logout
bash: logout: not login shell: use `exit'
root@adminit-OptiPlex-3010:/home/adminit# exit
exit
adminit@adminit-OptiPlex-3010:~$ login varun
login: Cannot possibly work without effective root
adminit@adminit-OptiPlex-3010:~$ sudo su
root@adminit-OptiPlex-3010:/home/adminit# login varun
Password:
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-41-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
0 updates can be installed immediately.
0 of these updates are security updates.

The list of available updates is more than a week old.


To check for new updates run: sudo apt update
Your Hardware Enablement Stack (HWE) is supported until April 2025.
Last login: Fri Feb 25 09:55:34 IST 2022 on pts/0
DEPARTMENT OF INFORMATION TECHNOLOGY / CLASS- SY / SEM-IV / SUB-UNIX LAB) / ACADEMIC YEAR-2021-22(EVEN) / VARUN KANBHAT (26)
K. J. SOMAIYA INSTITUTE OF ENGINEERING AND INFORMATION TECHNOLOGY, SION, MUMBAI-400022

varun@adminit-OptiPlex-3010:~$ passwd
Changing password for varun.
Current password: 
New password:
Retype new password:
passwd: password updated successfully
varun@adminit-OptiPlex-3010:~$ exit
logout
root@adminit-OptiPlex-3010:/home/adminit# exit
exit
adminit@adminit-OptiPlex-3010:~$

DEPARTMENT OF INFORMATION TECHNOLOGY / CLASS- SY / SEM-IV / SUB-UNIX LAB) / ACADEMIC YEAR-2021-22(EVEN) / VARUN KANBHAT (26)

You might also like