Professional Documents
Culture Documents
Lab 5 OS
Lab 5 OS
T / Ebtisam ALselwi 1
An introduction
T / Ebtisam ALselwi 2
Elements for user identification:
Login : The login name is used to access the system and two
users may not participate in the same The name .
Passwd : The password is used to access the system.
UID(user identification ): is number associated with login the
name.
GID( group identification) : Is a number associated with the
name of the group to which the user belongs it .
Comment: User description or comment does not require
writing.
home directory path: Home directory path for user .
The shell : is executed automatically when the user enters the
system and is usually / bin / bash .
T / Ebtisam ALselwi 3
Files for users:
T / Ebtisam ALselwi 4
Elements to define the group:
Name:
The group name is used to enter the group and may not share two
groups In the same name.
Passwd:
The password is used to access the group. In most cases, passwd is not
assigned to the group.
GID:
The definition of the group is a number associated with the name of the
group and may not carry two groups same Number .
User list:
List of users subscribed to the group.
T / Ebtisam ALselwi 5
Files for groups:
/ etc / group:
etc / gshadow:
This file contains confidential information about the
groups (Group password ).
T / Ebtisam ALselwi 6
User administration
Administrator Accounts
In Ubuntu, anyone in the sudo group can run any command (as long as
they use the sudo command when required).
To add an existing user to the "sudo" group (thus giving them admin
permissions) run:
ex:sudo adduser username
T / Ebtisam ALselwi 7
Managing Users and
Groups
Function
Command
T / Ebtisam ALselwi 8
Managing Users and
Groups(con…)
Function
Command
cat /etc/passwd The /etc/passwd file is the system user database. There is
an entry in this file for
every user on the system—a line consisting of attributes like
the Linux user name,
The entries in /etc/passwd have the following format:
⟨user name⟩:⟨password⟩:⟨UID⟩:⟨GID⟩:⟨GECOS⟩:⟨home
directory⟩:⟨shell⟩
T / Ebtisam ALselwi 9
Managing Users and
Groups(con…)
Function
Command
cat /etc/shadow The /etc/shadow File For security, nearly all current Linux
distributions store encrypted user passwords in the
/etc/shadow file (―shadow passwords‖).
this file contains one line for each user, with the following
format:
⟨user name⟩:⟨password⟩:⟨change⟩:⟨min⟩:⟨max⟩_
_:⟨warn⟩:⟨grace⟩:⟨lock⟩:⟨reserved⟩
T / Ebtisam ALselwi 10
Managing Users and
Groups(con…)
Function
Command
cat /etc/group grep Search in the system group database information in the
groupname /etc/group file.
T / Ebtisam ALselwi 11
Managing Users and
Groups(con…)
Function
Command
T / Ebtisam ALselwi 12
Managing Users and Groups(con…)
Function
Command
Function
Command
T / Ebtisam ALselwi 14
Managing Users and
Groups(con…)
Function
Command
userdel –fr username To delete a user account, you need to remove the user’s
entries from /etc/passwd and /etc/shadow, delete all
references to that user in /etc/group, and remove the user’s
home directory as well as all other files created or owned by
that user. If the
user has, e. g., a mail box for incoming messages in
/var/mail, that should also be
removed.
groupdel There is also a tool to remove group entries.
groupdel ⟨group name⟩
exit Exit
T / Ebtisam ALselwi 15
Users Commands
T / Ebtisam ALselwi 16
id Command
display user-id and group id's
std@ubuntu:~$ id
uid=1000(std) gid=1000(std)
groups=1000(std),4(adm),24(cdrom),27(sudo),30(dip),46(pl
ugdev),109(lpadmin),125(sambashare)
std@ubuntu:~$ id ebtisam
T / Ebtisam ALselwi 17
whoami Command
Used to display the login_name
std@ubuntu:~$ whoami
std
T / Ebtisam ALselwi 18
useradd Command
std@ubuntu:~$ sudo adduser ebtisam2
[sudo] password for std:
Adding user `ebtisam2' ...
Adding new group `ebtisam2' (1002) ...
Adding new user `ebtisam2' (1002) with group `ebtisam2' ...
Creating home directory `/home/ebtisam2' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for ebtisam2
Enter the new value, or press ENTER for the default
Full Name []: ebtisam2
Room Number []: 2
Work Phone []: 123
Home Phone []: 1245
Other []: 4
Is the information correct? [Y/n] y
T / Ebtisam ALselwi 19
std@ubuntu:~$ cat /etc/passwd
This file contains information
for each user(Users' names and
UIDs ).
.
.
.
std:x:1000:1000:ebtisam,,,:/home/std:/bin/bash
ebtisam:x:1001:1001:,,q,exit:/home/ebtisam:/bin/bash
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/bin/bash
T / Ebtisam ALselwi 20
cat /etc/passwd(con…)
Visual Shell
UID GID User’s
folder
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/bin/bash
User
passwd
name
This user runs services ,
he dos not long in system .
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
T / Ebtisam ALselwi 21
Add user with options
User Group
name name
UID
Password
T / Ebtisam ALselwi 22
Add user with options
std:x:1000:1000:ebtisam,,,:/home/std:/bin/bash
ebtisam:x:1001:1001:,,q,exit:/home/ebtisam:/bin/bash
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/bin/bash
ebtisam3:x:1003:1006::/home/ebtisam3:
u2:x:1080:1005::/home/uh2:
ebtisam5:x:1004:1007::/home/ebtisam4:
newuser2:x:1050:1050:newuser2,123,1452,4521,4521:/home/lab:/bin/bash
T / Ebtisam ALselwi 25
passwd Command Chang the password fo exiting user.
T / Ebtisam ALselwi 26
passwd command(con…)
std@ubuntu:~$ sudo su
[sudo] password for std:
root@ubuntu:/home/std# passwd ebtisam4
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@ubuntu:/home/std# passwd ebtisam4
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@ubuntu:/home/std#
T / Ebtisam ALselwi 27
“Switch User”. Allows you to switch to another
user's account
ebtisam@ubuntu:/home/std$
T / Ebtisam ALselwi 28
Exit command Exit
ebtisam@ubuntu:/home/std$ exit
exit
std@ubuntu:~$
T / Ebtisam ALselwi 29
userdel Command To delete a user account
T / Ebtisam ALselwi 30
“Switch User”. Allows
you to switch account to
root/superuser account
std@ubuntu:~$ sudo su
root@ubuntu:/home/std#
T / Ebtisam ALselwi 31
Id & whoami in root account
root@ubuntu:/home/std# id
uid=0(root) gid=0(root) groups=0(root)
root@ubuntu:/home/std# whoami
root
T / Ebtisam ALselwi 32
Id username in root account
root@ubuntu:/home/std# id std
uid=1000(std) gid=1000(std)
groups=1000(std),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmi
n),125(sambashare)
root@ubuntu:/home/std#
T / Ebtisam ALselwi 33
cat /etc/passwd
root@ubuntu:/home/std# cat /etc/passwd
This file contains information for
each user(Users' names and UIDs ).
Use this file in root a account
.
.
.\std:x:1000:1000:ebtisam,,,:/home/std:/bin/bash
ebtisam:x:1001:1001:,,q,exit:/home/ebtisam:/bin/bash
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/bin/bash
ebtisam3:x:1003:1006::/home/ebtisam3:
ebtisam4:x:1004:1007::/home/ebtisam4:
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/bin/bash
T / Ebtisam ALselwi 34
root@ubuntu:/home/std# cat /etc/shadow
root:!:17952:0:99999:7:::
This file contains
daemon:*:16365:0:99999:7:::
confidential
bin:*:16365:0:99999:7:::
information about
sys:*:16365:0:99999:7:::
users(users password
sync:*:16365:0:99999:7:::
).
games:*:16365:0:99999:7:::
man:*:16365:0:99999:7:::
lp:*:16365:0:99999:7:::
mail:*:16365:0:99999:7:::
news:*:16365:0:99999:7:::
uucp:*:16365:0:99999:7:::
proxy:*:16365:0:99999:7:::
www-data:*:16365:0:99999:7:::
backup:*:16365:0:99999:7:::
list:*:16365:0:99999:7:::
irc:*:16365:0:99999:7:::
gnats:*:16365:0:99999:7:::
nobody:*:16365:0:99999:7:::
syslog:*:16365:0:99999:7:::
T / Ebtisam ALselwi 35
cat /etc/passwd|grep command
std:x:1000:1000:ebtisam,,,:/home/std:/bin/bash
ebtisam:x:1001:1001:,,q,exit:/home/ebtisam:/bin/bash
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/bin/bash
ebtisam3:x:1003:1006::/home/ebtisam3:
ebtisam4:x:1004:1007::/home/ebtisam4:
root@ubuntu:/home/std#
T / Ebtisam ALselwi 36
cat /etc/passwd|grep command(con..)
std:x:1000:1000:ebtisam,,,:/home/std:/bin/bash
ebtisam:x:1001:1001:,,q,exit:/home/ebtisam:/bin/bash
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/bin/bash
ebtisam3:x:1003:1006::/home/ebtisam3:
ebtisam4:x:1004:1007::/home/ebtisam4:
root@ubuntu:/home/std#
T / Ebtisam ALselwi 37
cat /etc/passwd|grep command(con...)
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/
bin/bash
T / Ebtisam ALselwi 38
Groups Commands
T / Ebtisam ALselwi 39
Groupadd Command Create a new group:
T / Ebtisam ALselwi 40
cat /etc/group command This file contains
information for each
group(Group
std@ubuntu:~$ cat /etc/group names and GIDs ).
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
.
.
std:x:1000:
sambashare:x:125:std
ebtisam:x:1001:
ebtisam2:x:1002:
eng:x:1003:
eng1:x:1004:ebtisam2
eng2:x:1005:ebtisam3
ebtisam3:x:1006:
eng3:x:1007:
T / Ebtisam ALselwi 41
cat /etc/gshadow command
ebtisam:x:1001:
ebtisam2:x:1002:
eng1:x:1004:ebtisam2
eng2:x:1005:ebtisam3
ebtisam3:x:1006:
T / Ebtisam ALselwi 43
cat /etc/group|grep command
ebtisam2:x:1002:
eng1:x:1004:ebtisam2
T / Ebtisam ALselwi 44
Change a group’s name:
groupmod -n newgroupname oldgroupname
T / Ebtisam ALselwi 45
Delete a group: sudo delgroup groupname
T / Ebtisam ALselwi 46
Add and Change the group password: gpasswd grprname
T / Ebtisam ALselwi 47
Add a user to a new group: Usermod –G groupname username
T / Ebtisam ALselwi 49
Modifying information of
user & group
T / Ebtisam ALselwi 50
Modifying a user:
std@ubuntu:~$ sudo su ebtisam4
ebtisam4@ubuntu:/home/std$ usermod
Usage: usermod [options] LOGIN
Options:
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-a, --append append the user to the supplemental GROUPS
mentioned by the -G option without removing
him/her from other groups
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the
new location (use only with -d)
T / Ebtisam ALselwi 51
Modifying a user(con…):
std@ubuntu:~$ sudo su ebtisam4
ebtisam4@ubuntu:/home/std$ usermod
T / Ebtisam ALselwi 52
Modifying a username :
-std@ubuntu:~$ sudo su
ebtisam4
root@ubuntu:/home/std#
T / Ebtisam ALselwi 53
-root@ubuntu:/home/std# cat /etc/passwd
ebtisam:x:1001:1001:,,q,exit:/home/ebtisam:/bin/bash
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/bin/bash
ebtisam3:x:1003:1006::/home/ebtisam3:
u2:x:1008:1008::/home/uh2:
ebtisam5:x:1004:1007::/home/ebtisam4:
T / Ebtisam ALselwi 54
Modifying uid ‘s user:
.
.
std:x:1000:1000:ebtisam,,,:/home/std:/bin/bash
ebtisam:x:1001:1001:,,q,exit:/home/ebtisam:/bin/bash
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/bin/bash
ebtisam3:x:1003:1006::/home/ebtisam3:
u2:x:1080:1005::/home/uh2:
ebtisam5:x:1004:1007::/home/ebtisam4:
T / Ebtisam ALselwi 55
Modifying a Gid ‘s group :
.
.
std:x:1000:1000:ebtisam,,,:/home/std:/bin/bash
ebtisam:x:1001:1001:,,q,exit:/home/ebtisam:/bin/bash
ebtisam2:x:1002:1002:ebtisam2,2,123,1245,4:/home/ebtisam2:/bin/bash
ebtisam3:x:1003:1006::/home/ebtisam3:
u2:x:1008:1005::/home/uh2:
T / Ebtisam ALselwi 56
cat /etc/default/useradd command
T / Ebtisam ALselwi 57
cat /etc/login.defs
T / Ebtisam ALselwi 58
End…
T / Ebtisam ALselwi 59