I. file permissions management explain
1. Introduction Permissions
Linux file permissions for the three groups : users, user groups, other . We use the command ls -l or ll, to format the form of a list, you can view the file or directory corresponding to the rights information
A list of file character meaning information, file permissions total of 10 characters, and its significance are:
A, the first character of the file type
B, d: represents a file directory
C, -: represents a file
D, |: indicates that the connection file
E, b: means that the device files for storage interface device
F, c: inside the device file represents a serial port device, such as a keyboard
G, characters 2-4: User Permissions
H, fifth to seventh characters: User Group Permissions
I, 8 to 10 characters, and other user rights
For file permissions can be divided into three
Kind permission | value | description |
---|---|---|
r | 4 | Readable |
w | 2 | Writable |
x | 1 | Executable |
Case
It can be seen from the above information:
This file belongs to the user test, belong to the user group tlgroup
The file permissions for the user rw-, that is, you can read and write permissions
The file permissions for the user group is r-, namely read permission
The other file permissions r-, that is readable permissions
coding and shell script executable permissions
-
Before the course used a script to enhance the installation script tools: ./ VBoxLinuxAddtions.run
-
Shell scripting, shell scripts to achieve output HelloWorld
New start.sh, touch start.sh. Write shell Source:
#!/bin/bash
echo “HelloWorld!”
- Assigned to the script executable permissions, chmod 744 start.sh
- shell script execution
A, performed in the current path, cd to the directory where the start.sh performed ./start.sh
B, you may also be performed using an absolute path, / root / tianliang / start.sh
C, sh scripts directly called for execution
D, source script is executed directly affect the current session window
2. Common Commands
chmod:更改文件、文件夹权限。权限设置分2种,分别可以使用数字和符号。
语法:chmod [-R] 权限
文件/目录
选项与参数:-R递归的持续更改,连同子目录下的所有文件一起更改
数字修改法
使用ll input.txt查看文件原来权限,使用chmod 755 input.txt更改权限,修改后,使用ll input.txt再次查看文件权限。
符号修改法
使用ll input.txt查看原始权限,使用chmod u=rwx,g=rwx,o=rwx
input.txt,修改后再次使用ll input.txt查看文件权限。
chown:更改文件所有者。此命令是change owner的简称,不过要被改变的用户要在/etc/passwd文件内存在才行,否则会报错,一般为root用户调用较多。
语法:chown [-R] 用户
文件/目录 或者 chown [-R] 用户:组名 文件/目录
选项与参数:-R递归参数(recursive)的级联更改,连同子目录下的所有文件一起更改。
更改文件的用户名和所属组:chown test:test
input.txt
更改文件夹的所属用户名:chown -R test data
更改文件夹所属的用户组:chown -R :test data
chgrp:更改文件所属用户组。此命令是change group的简称,要求被改变的组名要在/etc/group文件内存在才行,否则会报错。
语法:chgrp [-R] 用户组 文件/目录
选项与参数:-R 递归的级联更改,连同子目录下的所有文件一起更改。
递归更改文件夹所属用户组:chgrp -R test data
二.系统常用服务与管理
1.常用服务
- 防火墙服务-开启与关停
service iptables restart/stop/status
- ssh服务-开启与关停
service sshd restart/stop
- httpd服务-开启与关停
service httpd restart/stop
- network服务-开启与关停
service network restart/stop
- 网络时间同步服务ntpd-开启与关停
service ntpd restart/stop
2.永久改变服务的状态-重启机器后依然后效
解决方法
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行信息。切记chkconfig不是立即自动禁止或者激活一个服务,它只是简单的改变了符号连接。如果想及时生效,必须用service来start和stop。
使用语法
chkconfig
[–add][–del][–list][系统服务] 或
chkconfig
[–level<等级代号>] [系统服务]
[on/off/reset]
参数用法
-
add:增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。
-
del:删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。
-
level<等级代号>:指定读系统服务要在哪一个执行等级中开启或关闭。
Level 0 : Indicates shutdown
Level 1 : single-user mode
Level 2 : Multi-user command line mode without network connection
Level 3 : There is a multi-user network connection command line
Level 4 : Not available
Level 5 : Multi-user mode with GUI
Level 6 : Restart
It should be noted, level option to specify the level you want to view the run is not necessarily the current run level. For each run level, only one startup script or a stop script. When switching run level, init does not restart the service has been launched, it will not have to stop to stop the service again.
Examples of use
chkconfig
-list: lists all system services
chkconfig
-add httpd: httpd service increase
chkconfig
-del httpd: httpd service delete
chkconfig
-Level 2345 on httpd: httpd running level set for the state in the case of 2,3,4,5 are turned on.
chkconfig
-list mysqld: lists the cases mysqld service settings
chkconfig
mysqld ON: set mysqld running in each level are open