Tải bản đầy đủ (.pdf) (10 trang)

033 lab 2 kho tài liệu training

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (290.26 KB, 10 trang )

Lab 2

Goal: Become familiar with file permissions and modification
commands

System Setup: A working installed Centos Linux
LAB 2 Instructions:
PART 1:
1- Login to the system as user "root"
2- Run the command "cd "
"cd"
3- Run the command "pwd" to print your work directory
"pwd"
You should see the output result /root
4- Run the command "cat /etc/passwd" and check the last 6
lines
"cat /etc/passwd" you should see the output result
jamal:x:500:500::/home/jamal:/bin/bash
tork:x:501:501::/home/tork:/bin/bash
omar:x:502:502::/home/omar:/bin/bash
student:x:503:504::/home/student:/bin/bash
udemy:x:504:505::/home/udemy:/bin/bash
mostafa:x:505:506::/home/mostafa:/bin/bash
What is ":x:" ?


5- Add a new user using the "adduser" command
"adduser ali"
6- Display the "/etc/passwd" contents again
"cat /etc/passwd"
Check the last line !!


7- Display the "/etc/shadow" contents
"cat /etc/shadow" and check the last line , you should see
mostafa:!!:16072:0:99999:7:::
why there's no password in the 2 nd field and what does
99999 refers to ?
8- Set password "typo100" for user "ali"
"passwd ali"
9- Display the "/etc/shadow" contents
"cat /etc/shadow" and check the last line again , do you
see the encrypted password for user "ali" ?
10Edit "/etc/login.defs"
"vi /etc/login.defs"
Change " PASS_MAX_DAYS" value to "72" then save and
exit the file , what do "PASS_MAX_DAYS" do ?
11Delete user "ali"
"userdel ali"
12Change your working directory
"cd /home"


13Run the "ls" command to display user's home
directories
"ls"
Why the user "ali" home directory still exists if we deleted
the user "ali" using the "userdel" command ?
14Remove ali's home directory using the "rm"
command (self assignment)
15To delete the user and his home directory run the
"userdel –r"
"userdel –r student"

16Run the "ls" command to display user's home
directories
"ls"
Is student's home directory exist ?
17Run the command "chage –l tork" to display
information about this user
"chage –l tork"
The result output will be something like
Last password change
: Dec 21, 2013
Password expires
: never
Password inactive
: never
Account expires
: never
Minimum number of days between password change
Maximum number of days between password change
Number of days of warning before password expires

:0
: 99999
:7

18Change the Minimum number between password
change by running the command "chage"
"chage –m 3 tork"
19Run the command "chage –l tork" again
"chage –l tork"
What's the Minimum number of days between password

change now ?


20Change the maximum number of days between
password change & number of days of warning before
password expire for user "tork" (self assignment)
21Run the "chage –l tork" command after you finishing
your modification
"chage –l tork"
22Display the "/etc/group" file content and check the
last 2 lines
"cat /etc/group"
You should see
udemy:x:505:
mostafa:x:506:
Note that when you create a new user to the system , a
group created automatically for this user with the same
username.
23Add two groups to the system
"groupadd sales"
"groupadd it"
24Display "/etc/group" file content and check the last
2 lines
"cat /etc/group"
Do you see the new groups you added to the system ?
what is the groups IDs?
25Display user id and groups for a user
"id tork"
You should see
uid=501(tork) gid=501(tork) groups=501(tork)



Note that user tork is in the group "tork"
26Add user "tork" to the group "sales"
"usermod -aG sales tork"
27Run the "id" command to display user "tork" uid and
groups.
"id tork"
You should see
uid=501(tork) gid=501(tork) groups=501(tork),503(sales)
28Delete group "sales""
"groupdel sales"
29Run the "id tork" and check if user tork still member
in the group "sales" or not
"id tork"
PART 2:
1- Change your current work directory
"cd /home"
2- Create a new directory "shared"
"mkdir shared"
3- Display directory permissions
"/ls –l"
You should see the result
drwxr-xr-x. 2 root root
drwx------. 4 tork tork

4096 Jan 3 01:33 shared
4096 Jan 2 11:29 tork

Any new created directory has the permission "755" by

default , but the home directory of a user , has the
permission 700 , why is that ?


4- Change your current work directory
"cd /home/shared"
5- Create a new file
"touch shared.txt"
6- Display the file permissions
"ls –l shared.txt"
You should see the result
-rw-r--r--. 1 root root 0 Jan 3 01:58 shared.txt
Any new created file has the permission "644" by
default , which means
Read, write= Owner
Read= Group
Read= Others
7- Now add contents in the file by the command "seq"
"seq 10 > shared.txt"
8- Display the file content
"cat shared.txt" you should see the result
[root@bird shared]# cat shared.txt
1
2
3
4
5
6
7
8

9
10

9- Switch to user "tork" using the command "su"
"su tork"
10- Run the command "pwd" to check your current
work directory


You should see the result
/home/shared
11- Run the command "whoami" to check which user
logged in
"whoami" you should see the result:
tork
12- Display the "shared.txt" contents
"cat shared.txt" you should see the result :
1
2
3
4
5
6
7
8
9
10

13- Now add contents in the file by the command "seq"
"seq 5 > shared.txt"

You should see the result:
[tork@bird shared]$ seq 5 > shared.txt
bash: shared.txt: Permission denied

you can't edit or add contents to this file because you
are logged in with the user tork , you only have the
"read" permission.
14- Create a new file
"touch tork.txt" you should see the result:
[tork@bird shared]$ touch tork.txt
touch: cannot touch `tork.txt': Permission denied


you can't create files or directories in the "shared"
directory because you are logged in with the user tork ,
you only have the "execute" permission.
15- Switch to user "root"
"su –"
Note that the system will ask you to enter the root's
password.
16- Run the command "pwd"
You should see the result : /root
17- Change your working directory to "/home"
"cd /home"
18- Change the "shared" directory permission to "757"
"chmod 757 shared"
19- Change your working directory to the "shared"
"cd shared"
20- Change the "shared.txt" permission to 666
"chmod 666 shared.txt"

21- Switch to user tork
"su tork"
22- Display the content of the "shared.txt"
"cat shared.txt" you should see the result:
[tork@bird shared]$ cat shared.txt
1
2
3
4
5
6
7
8
9
10


23- Try now to add a contents to the "shared.txt" using
the command "seq"
"seq 5 > shared.txt"
Did you notice that you didn't get a permission error
message?
24- Display the "shared.txt" contents
"cat shared.txt" you should see the result:
[tork@bird shared]$ cat shared.txt
1
2
3
4
5


25- Create a new file "tork.txt"
"touch tork.txt"
26- Run the command "ls –l tork.txt" to check the files
permission
You should see the result:
-rw-rw-r--. 1 tork tork 0 Jan 3 04:38 tork.txt

This file has the read, write permissions to the file
owner and the group
27- Change the "tork.txt" group to "it"
"chmod –R :it tork.txt" you should see the result:
[tork@bird shared]$ chown -R :it tork.txt
chown: changing group of `tork.txt': Operation not permitted

and that's because the user "tork" doesn't have the
permission to change the group of a file .
28- Switch to user "root"


"su –"
29- Change the working directory
"cd /home/shared"
30- Change the "tork.txt" group to "it"
"chmod –R :it tork.txt"
31- Self assignment
a- Add user "mostafa" to the group "it"
b- Switch to user "mostafa"
c- Add contents to file "tork.txt" using the "seq"
command

Linux Crash Course @ udemy.com
Thank you
Muhammed Tork



×