Experiment 3:unix/linux permissions and file management commands __linux

Source: Internet
Author: User
Tags chmod mkdir touch virtual environment
experiment 3:unix/linux permissions and file management commands 1. Experimental purposes

Unix/linux permissions and file management commands;

The use of Unix/linux file system;

Other commands related to file system administration. 2, the realization of equipment

A server or computer with a Linux system installed with a virtual environment Linux system Windows operating system. 3. Experimental methods and matters needing attention

1 User name: root password: 123456

2 because it is a root user, the power is very large, please do not in the system or other users do not secure things.

3 require each classmate to log in after the system, in their own home directory content in their own (Hanyu Pinyin) name, using the mkdir command to create a subdirectory. All future work will be done in your own catalogue.

4) to be written in earnest the experiment report. 4, the experimental process (l) using LS to observe the properties of a file

Use the LS command to list the contents of the sample directory in different formats, and use the man command when necessary to refer to the usage of the LS command:

Ls–l/dev/hda? /dev/tty? /Network | Less

Ls–la/dev/hda? /dev/tty? /Network | Less

Ls–lai/dev/hda? /dev/tty? /Network | Less

Observe the type and attributes of the file. (2) umask value and umask command when creating files and directories, the system will set the default permissions for them. The default permissions for a file or directory are file rights masks (Umask) to control, and users use command Umask to set or display the value of the current file or directory creation umask. At the default value of 0022.

A. Use the command: Umask or umask–p or umask–s to view the current Umask value and make a record.

1, [Root@localhost root]# umask
0022

2, [Root@localhost root]# umask-p
Umask 0022

3, [Root@localhost root]# umask-s
U=rwx,g=rx,o=rx


B. Use file management commands, such as Touch myfile create a new file myfile, use directory management commands, such as mkdir Mydir create a new directory Mydir, use the command stat or ls–l to check the properties of the newly created file.

[Root@localhost root]# Stat myfile


File: ' MyFile '
Size:50 blocks:8 IO block:4096 Regular File
device:802h/2050d inode:293518 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
Access:2016-04-27 14:20:07.000000000 +0800
Modify:2016-04-27 14:20:07.000000000 +0800
Change:2016-04-27 14:20:07.000000000 +0800

[Root@localhost root]# Ls-l
Total Dosage 112
-rwxr-xr-x 1 root root 11826 March 15:20 a.out
-rwxr-xr-x 1 root root 12284 2014-04-16 app
-rw-r--r--1 root root 402 2014-04-16 app.c
-rw-r--r--1 root root 1003 2014-04-16 copy.c
Drwxr-xr-x 2 root root 4096 March 15:32 dda
-rw-r--r--1 root root 137 March 15:22 dir.out
-rw-r--r--1 root root 1 March 15:46 Dispallvar
-rwxr-xr-x 1 root root 13315 2014-04-16 E
-rw-r--r--1 root root 34 March 15:25 Err.out
Drwxr-xr-x 2 root root 4096 April 14:20 Gaozhen
-rw-r--r--1 root root 50 April 14:20 myfile
-rwxr-xr-x 1 root root 13355 2014-04-16 s
-rw-r--r--1 root 2014-04-16 s.cpp
-rw-r--r--1 root root 1996 2014-04-16 S.O
-rwxr-xr-x 1 root root 11826 2014-04-16 t
-rw-r--r--1 root root 318 2014-04-16 t.c

C. Use the command UMASK UMASK (for example, UMASK 0007) to set a new UMASK value. Then use commands like touch Myf to create a new file Myf, use the command mkdir myd to create a new directory myd, use the command stat or ls–l to check the properties of the newly created file, and compare the differences from the default umask.

[Root@localhost gaozhen]# umask 0007 #设置新值
[Root@localhost gaozhen]# umask #查看umask的值
0007

Create a file with this umask value, and then use Stat to view the status of the file


[Root@localhost gaozhen]# Touch Myf
[Root@localhost gaozhen]# stat MYF
File: ' Myf '
size:0 blocks:0 IO block:4096 Regular File
device:802h/2050d inode:163999 links:1

Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) (0022)


Access: (0660/-RW-RW----) Uid: (0/root) Gid: (0/root) (0007)


Access:2016-04-27 14:32:57.000000000 +0800
Modify:2016-04-27 14:32:57.000000000 +0800
Change:2016-04-27 14:32:57.000000000 +0800



D. Try to analyze the effects and effects of umask values on newly created files and directories. (3) Use Rights Management command chmod to set permissions

Modify permissions for MYF or directory myd (check the file attributes with Ls–l for each step you complete):

[Root@localhost gaozhen]# Ls-l myfile
-rw-r--r--1 root root 0 April 14:30 myfile

Add other people's access and read permissions for the directory myd: chmod o+rx myd

[Root@localhost gaozhen]# chmod O+rx myfile
[Root@localhost gaozhen]# Ls-l myfile
-rw-r--r-x 1 root root 0 April 14:30 myfile



To remove write permissions for the same group of people for directory MyD and file Myf: chmod g-w myd MYF

[Root@localhost gaozhen]# ls-l myfile MYF


-RW-RW----1 root 0 April 14:32 Myf
-rw-r--r-x 1 root root 0 April 14:30 myfile
[Root@localhost gaozhen]# chmod g-w myfile MYF


[Root@localhost gaozhen]# Ls-l *


-rw-r-----1 Root 0 April 14:32 Myf
-rw-r--r-x 1 root root 0 April 14:30 myfile


To set the permissions for directory MyD and file Myf to read-writable executable: chmod 777 myd MYF

[Root@localhost gaozhen]# Stat *
File: ' Myf '
size:0 blocks:0 IO block:4096 Regular File
device:802h/2050d inode:163999 links:1
Access: (0777/-rwxrwxrwx) Uid: (0/root) Gid: (0/root)
Access:2016-04-27 14:32:57.000000000 +0800
Modify:2016-04-27 14:32:57.000000000 +0800
Change:2016-04-27 14:49:12.000000000 +0800

File: ' MyFile '
size:0 blocks:0 IO block:4096 Regular File
device:802h/2050d inode:163992 links:1
Access: (0777/-rwxrwxrwx) Uid: (0/root) Gid: (0/root)
Access:2016-04-27 14:30:24.000000000 +0800
Modify:2016-04-27 14:30:24.000000000 +0800
Change:2016-04-27 14:49:12.000000000 +0800

To get rid of other people's permission access to directory MyD and file Myf: chmod o-rwx myd MYF

[Root@localhost gaozhen]# Ls-l *
-rwxrwxrwx 1 root root 0 April 14:32 Myf
-rwxrwxrwx 1 root root 0 April 14:30 myfile
[Root@localhost gaozhen]# chmod o-rwx *
[Root@localhost gaozhen]# Ls-l *
-RWXRWX---1 root 0 April 14:32 Myf
-RWXRWX---1 root 0 April 14:30 myfile


The permissions for directory MyD and file Myf are set to the user and the same group of people can read and write executable, while others are inaccessible: chmod 770 MYF MyD

[Root@localhost gaozhen]# chmod 770 myfile MYF
[Root@localhost gaozhen]# Ls-l *
-RWXRWX---1 root 0 April 14:32 Myf
-RWXRWX---1 root 0 April 14:30 myfile

Set permissions for all files and subdirectories under the system temp directory to 777:chmod–r 777/tmp/* (4) using CHOWN,CHGRP, and so on

The ability to use the Rights Management Command Chown (change owner) is a user or group that changes files, and only superuser can use the command.


Ch[root@localhost root]# useradd test1 #添加用户


[Root@localhost root]# grep Test1/etc/passwd/etc/group/etc/shadow

#查看grep Test1/etc/passwd/etc/group/etc/shadow File changes


/etc/passwd:test1:x:504:504::/home/test1:/bin/bash
/etc/group:test1:x:504:
/etc/shadow:test1:!! : 16918:0:99999:7::
[Root@localhost root]# Cd/etc/login.defs
BASH:CD:/etc/login.defs: Not directory GRP, etc. permission settings (for each step of the operation to use the Ls–l check file properties and record):

/etc/login.defs: In a Linux system, creating a user's home directory when creating a user depends on the value of the variable create_home in the/etc/login.defs file, or the default creation of the home directory if yes, or by using the-m parameter to force creation.

Set the directory myd user master to Adm:chown ADM MyD

Set the group of directory MyD and file Myf to lp:chgrp LP MyD MYF

Set the user master for the directory MyD and all of its subdirectories to ADM, with the group set to Bin:chown-r Adm:bin myd

Set the primary and group of the directory/var/www and its subdirectories to Apache:chmod-r apache:apache/var/www (5) Users who create Non-default properties

Create two users User1 and User2, make them all in an existing group (such as COGRP, if not present, create them with Groupadd before creating users), and use the same working directory (such as/home/codir), and ensure that each user can log in successfully and work. The process is as follows:

A. Creating a public group Cogrp:groupadd COGRP #若组cogrp已经存在则不需要创建

B. Create User1:useradd–d/home/codir–g Cogrp user1

C. Create User2:useradd–d/home/codir–g cogrp User2

D. Modify permissions for the public directory to have RWX permissions for the same group: chmod G+rwx/home/codir

E. Set password as root for User1 and User2: passwd user1;passwd user2

Log in User1 and User2, respectively, on a different character interface.

Changes in/etc/passwd,/etc/group,/etc/shadow, and/home can be observed in the above steps. (6) Ext2 and Ext3 Extended file attribute management

A. View extended properties for newly created files: lsattr MYF

B. Adding extended properties for MyD and Myf: chattr +i MYF

C. Re-view extended properties for MyD and Myf: lsattr MYF

D. Attempt to delete file Myf with extended attribute I, observe the process and the results, why.

E. Remove Myf I extended permissions, and then delete the file to see how the results.

Chattr–i MYF rm–f Myf (7) Shutdown system

After completing the above tasks, you can also experiment with what you have already learned, and you can also have content that is of interest in the former malleable or Linux system.

After the experiment is finished, the system shuts down normally. 5, the content and writing of the experiment report

Record every step of your process in writing, including input, output information, problems encountered and solutions, (the output can be streamlined).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.