反掩码
每个用户在创建的时候都会有一个默认权限,这个默认权限是由 umask
值来决定的,又称之为 反掩码
在前一篇文章中有提到文件权限如 777
等
777代表的就是4+2+1
而umask反掩码则是反着来的,它是从6开始减(默认就是没有执行权限)
普通用户的默认的权限是 002
所以666-002=664
创建出来的文件就是这样的
-rw-rw-r--
6 6 4
命令:umask <值>
无论运行命令的用户是谁,最终执行的身份为文件的所有者。同时该命令必须为可执行文件,且该用户有该文件的执行权限
代表的命令: /bin/passwd
适用范围:文件所有者权限
用人话来举个例子
在系统中,有一个可执行文件,该文件的所有者为 root
用户,那么别的用户在使用这条命令的时候,就会以该文件的所有者 root
用户的身份来执行
那么权限配置不当的可执行文件有什么危害呢
首先,在Linux系统中,有一个命令是 ifconfig
,用户可以通过该命令来对系统的网卡进行开启和关闭操作
ifconfig
同时也是一个可执行文件,该文件默认的权限为 755
如果我们的普通用户想要尝试关掉网卡呢,是没有权限的
而如果我们给 /sbin/ifconfig
添加一个setuid权限
原本执行的地方变成了s,而且文件名变成红色了(提醒说这个可执行文件权限过大)
这时候我们普通用户执行的时候,就是已文件所有者,也就是 root
用户的身份去执行的
网卡可以关闭了
1.进程 :程序运行的内存态的数据,动态 , 占用CPU,MEM , IO 主进程 和 子进程 , 一个主进程可以产生多个子进程 ,当主进程结束之后,子进程也会终止, 多个主进程之间是相互独立 ,有独立的CPU时间和内存地址空间。
2.进程ID:在系统中的唯一的编号
3.查看进程状态:ps -aux
杀掉进程 kill:
数值为1 重读配置文件,不会真正的Killed掉进程
数值为9 强制终止
数值为15 默认关闭,正常终止
举个例子,我这里想强制kill掉http服务的进程,首先,通过
service httpd status
来确定进程ID,然后,发送9这个指令过去
调整进程优先级:修改进程nice值
nice值是Linux程序中用来表明程序优先级的值,范围从-20(最高优先级)到19(最低优先级)
命令:nice -n<程序>
1.服务管理程序 启停 开机自启 ,状态 ,日志,意外终止 恢复等等
2.服务的配置文件:/lib/systemd/system
软件安装之后默认服务配置保存位置
[root@server0 ~]# cd /lib/systemd/system
[root@server0 system]# pwd
/lib/systemd/system
[root@server0 system]# ls
accounts-daemon.service plymouth-read-write.service
alsa-restore.service plymouth-reboot.service
alsa-state.service plymouth-start.service
anaconda-direct.service plymouth-switch-root.service
anaconda-nm-config.service polkit.service
anaconda-noshell.service poweroff.target
anaconda-pre.service poweroff.target.wants
anaconda.service printer.target
anaconda-shell@.service proc-fs-nfsd.mount
anaconda-sshd.service proc-sys-fs-binfmt_misc.automount
anaconda.target proc-sys-fs-binfmt_misc.mount
anaconda-tmux@.service psacct.service
arp-ethers.service qemu-guest-agent.service
atd.service qemu-pr-helper.service
3.自定义的配置关联关系:
[root@server0 system]#
[root@server0 system]# cd /etc/systemd/system/
[root@server0 system]# pwd
/etc/systemd/system
[root@server0 system]# ls
basic.target.wants nfs-blkmap.service.requires
bluetooth.target.wants nfs-idmapd.service.requires
dbus-org.bluez.service nfs-mountd.service.requires
dbus-org.fedoraproject.FirewallD1.service nfs-server.service.requires
dbus-org.freedesktop.Avahi.service printer.target.wants
dbus-org.freedesktop.ModemManager1.service remote-fs.target.wants
dbus-org.freedesktop.NetworkManager.service rpc-gssd.service.requires
dbus-org.freedesktop.nm-dispatcher.service rpc-statd-notify.service.requires
dbus-org.freedesktop.timedate1.service rpc-statd.service.requires
default.target sockets.target.wants
display-manager.service sysinit.target.wants
getty.target.wants syslog.service
graphical.target.wants systemd-timedated.service
multi-user.target.wants timers.target.wants
network-online.target.wants vmtoolsd.service.requires
[root@server0 system]#
target: 多个相关服务组一个target
serivce: 服务 **
socket: 网络服务 **
path: 指定服务位置运行
系统常用的target:
graphical.target: 图形化已包含了multi-user.target 所有service
[root@server0 system]# systemctl get-default #查看当前的运行target # chkconfig --level 5
multi-user.target
[root@server0 system]#
4.查看服务状态:(可用service或systemctl)
[root@server0 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server # 描述
Loaded: loaded (/usr/lib/systemd/system/httpd.service #配置文件; disabled #开机禁用; vendor pres>
Active: active (running) since Sat 2019-09-28 16:02:06 CST; 35s ago #状态
Docs: man:httpd.service(8) # man 8 httpd.service
Main PID: 2711 (httpd) #主进程ID
Status: "Running, listening on: port 80"
Tasks: 213 (limit: 12391)
Memory: 46.1M #内存空间占用
CGroup: /system.slice/httpd.service # 资源控制 RH442
├─2711 /usr/sbin/httpd -DFOREGROUND
├─2712 /usr/sbin/httpd -DFOREGROUND
├─2714 /usr/sbin/httpd -DFOREGROUND
├─2727 /usr/sbin/httpd -DFOREGROUND
└─2741 /usr/sbin/httpd -DFOREGROUND
Sep 28 16:02:05 server0.example.com systemd[1]: Starting The Apache HTTP Server>
Sep 28 16:02:06 server0.example.com httpd[2711]: Server configured, listening o>
Sep 28 16:02:06 server0.example.com systemd[1]: Started The Apache HTTP Server. #日志
lines 1-18/18 (END)
停止服务:
systemctl stop httpd
[root@server0 /]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor pres>
Active: inactive (dead)
Docs: man:httpd.service(8)
5.开机启动服务:
[root@server0 /]# systemctl enable httpd #使能服务开启启动
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@server0 /]#
[root@server0 /]#
[root@server0 /]#
[root@server0 /]# systemctl is-enabled httpd
enabled
[root@server0 /]# systemctl is-active httpd
active
[root@server0 /]#
[root@server0 /]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2019-09-28 16:07:44 CST; 4min 35s ago
Docs: man:httpd.service(8)
Main PID: 3338 (httpd)
6.开机禁用
[root@server0 /]#
[root@server0 /]# systemctl disable httpd
Removed /etc/systemd/system/multi-user.target.wants/httpd.service.
[root@server0 /]#
[root@server0 /]#
[root@server0 /]#
[root@server0 /]# systemctl is-enabled httpd
disabled
[root@server0 /]#
7.查看所有运行的服务的状态:
[root@server0 /]# systemctl list-units --type service
8.查看所有已安装的服务
[root@server0 system]# systemctl list-unit-files --type service
UNIT FILE STATE
accounts-daemon.service enabled #开机启动
alsa-restore.service static # 静态 此服务由其他服务调用
alsa-state.service static
anaconda-direct.service static
anaconda-nm-config.service static
anaconda-noshell.service static
anaconda-pre.service static
anaconda-shell@.service static
anaconda-sshd.service static
anaconda-tmux@.service static
anaconda.service static
arp-ethers.service disabled #禁用
atd.service enabled
auditd.service enabled
auth-rpcgss-module.service static
autovt@.service enabled
avahi-daemon.service enabled
blivet.service static
blk-availability.service disabled
bluetooth.service enabled
bolt.service static
brltty.service disabled
使用mask参数来禁用某服务,反之用umask取消禁用
10.查看服务的依赖关系:
[root@server0 ~]# systemctl list-dependencies sshd.service