1.umask
umask ##系统建立文件
umask 077 ##临时设定系统预留权限为077
目录:700
文件:600
永久修改umask
vim /etc/profile
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then ##系统配置文件
umask 002 ##普通用户的umask
else
umask 022 ##超级用户的umask
fi
vim /etc/bashrc ##shell的配置文件
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then ##shell的配置文件
umask 002
else
umask 022
fi
2.特殊权限
1.sticky ##粘制位
作用:只针对目录生效,当一个目录上有sticky权限时,在这个目录中的文件只能被文件的所有者删除
设定方式: chmod o+t dir
chmod 1xxx dir
2.sigd ##强制位
作用:
对文件:只针对二进制可执行文件。当文件上有sigd时,任何人执行此文件产生的进程都属于文件的组
对目录:当目录上有sigd时,任何人在此目录中建立的文件都属于目录的所有组
设定方式:chmod g+s file|dir
chmod 2xxx file|dir
3.suid ##冒险位
作用:只针对二进制可执行文件。当文件上有suid时任何人执行这个文件中产生的进程都属于文件的所有人
设定方式:chmod u+s file
chmod 4xxx file
3.acl权限列表
1.作用:让特定的用户对特定的文件拥有特定的权限
2.acl列表查看
getfacl file ##查看acl开启的文件权限
# file: file ##文件名称
# owner: root ##文件所有者
# group: root ##文件所有组
user::rw- ##文件所有人的权限
user:xxx::rwx ##指定用户的权限
group::r-- ##文件所有组的权限
mask::rwx ##能赋予用户的最大权力阀值
other::r-- ##其他人的权限
3.acl列表的管理
setfacl -m u:username:rwx file ##设定username对file拥有rwx权限
setfacl -m g:group:rwx file ##设定group组成员对file拥有rwx权限
4.mask值
在权限列表中mask表示能生效的权力值。当用chmod减小开启acl的文件权限时,mask值会发生变化
chmod g-w user ##看到减掉时的mask值
恢复mask值:
setfacl -m m:rwx user ##acl默认权限只针对目录设定
setfacl -m d:u:user1:rwx /mnt/user2 ##acl权限只针对设定完成之后建立的文件或目录生效,而已经存在的文件是不会继承默认权限的
4.系统进程及服务的控制
1.查看进程
1)图形方式查看
gnome-system-monitor
2)进程查看命令
ps -A ##所有进程
ps -a ##当前环境中运行的进程,不包含环境信息
ps -u ##显示进程中的用户信息
ps a ##在当前环境中运行的进程
ps x ##列出系统中所有运行包含tty输出设备
ps f ##显示进程的父子关系
ps e ##显示进程的详细信息(系统资源的调用)
3)常用组合
ps aux ##显示系统中所有进程并显示进程用户
ps ef ##显示进程详细信息并显示进程的父子关系
ps ax ##显示当前系统中的所有进程
5)显示进程指定信息
ps -o xxx 显示进程的指定信息
ps -o comm 显示进程名称
ps -o user 显示进程所有人
ps -o group 显示进程所有组
ps -o %cpu 显示进程cpu使用率
ps -o %mem 显示进程内存使用率
ps -o pid 显示进程的id
ps -o nice 显示进程的优先级
6)进程排序
ps ax --sort= +%cpu|-%cup|+%mem|-%mem
3.进程的优先级
S ##进程状态
l ##内存中有锁定空间
N ##优先级低
< ##优先级高
+ ##前台运行
s 顶级运行
1)优先级范围
-20~19
2)优先级查看
ps ax -o pid,nice,comm
3)改变进程的优先级
renice -n 优先级数字 进程id
[root@localhost Desktop]# renice -n -5 3452
3452 (process ID) old priority -5, new priority -5
4)指定某个优先级开启进程
nice -n 优先级数字 进程id
[root@localhost Desktop]# nice -n -5 vim &
[1] 13960
4.环境中进程的前后台调用
jobs ##查看被打入环境后台的进程
ctrl+z ##把占用终端的进程打入后台
fg jobsnum ##把后台进程调回前台
bg jobsnum ##把后台暂停的进程运行
comm & ##让命令直接在后台运行
5.进程信号
常用进程信号等级:
1 ##进程重新加载配置
2 ##删除进程在内存中的数据
3 ##删除鼠标在内存中的数据
9 ##强行结束单个进程(不可被阻塞)
15 ##正常关闭进程(可能会被阻塞)
18 ##运行暂停的进程
19 ##暂停某个进程(不可被阻塞)
20 ##把进程打入后台(可以被阻塞)
man 7 signal ##查看信号详细信息
kill -信号 进程 id
killall -信号 进程名字
pkill -u user -信号
6.进程的动态监控
top 1 ##显示cpu每个核的负载
top 1 ##显示cpu每个核的负载
top 1 ##显示cpu每个核的负载
top 1 ##显示cpu每个核的负载
top 1 ##显示cpu每个核的负载
7.控制服务
1)用什么控制服务
系统初始化进程可以对服务进行相应的控制
2)当前系统初始化进程是什么
systemd ##系统初始化进程
pstree ##显示系统中的进程树
3)进程控制命令
ssh————>sshd
client server
systemctl ##服务控制命令
systemctl status 服务 ##查看服务状态,inactive(不可用),active(可用ps ax -o pid,nice,comm 0)
[root@localhost Desktop]# systemctl status sshd
sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
Active: active (running) since Wed 2018-10-10 23:46:12 EDT; 10h ago
Process: 1245 ExecStartPre=/usr/sbin/sshd-keygen (code=exited, status=0/SUCCESS)
Main PID: 1264 (sshd)
CGroup: /system.slice/sshd.service
└─1264 /usr/sbin/sshd -DOct 10 23:46:12 localhost systemd[1]: Started OpenSSH server daemon.
Oct 10 23:46:12 localhost sshd[1264]: Server listening on 0.0.0.0 port 22.
Oct 10 23:46:12 localhost sshd[1264]: Server listening on :: port 22.
Oct 11 00:35:33 localhost sshd[3724]: Accepted password for root from 172.2...h2
Oct 11 04:15:16 localhost sshd[10380]: Accepted password for root from 172....h2
Hint: Some lines were ellipsized, use -l to show in full.[1]+ Stopped nice -n -5 vim
systemctl start 服务 ##开启服务
systemctl stop 服务 ##关闭服务
systemctl restart 服务 ##重启服务
systemctl reload 服务 ##重新加载服务配置
systemctl enable 服务 ##设定服务开机启动
systemctl disable 服务 ##设定服务开机不启动
systemctl list-units ##列出已经开启服务的启动状态
systemctl list-units-files ##列出所有服务开机启动状态
systemctl list-dependencies ##列出服务依赖
systemctl set-default multi-uuser.target ##设定系统启动级别为多用户模式(无图形)
systemctl set-default graphical.target ##设定系统启动级别为图型模式
5.sshd服务
1.sshd简介
sshd=secure shell ##可以通过网络在主机中开启shell服务
客户端软件:ssh
连接方式:第一次连接陌生主机时要建立认证文件,会询问是否建立,需要输入yes。再次连接此主机时,因为已经生成~/.ssh/know_hosts
远程复制:
scp file root@ip:dir ##上传(dir为绝对路径)
scp root@ip:file dir ##下载(file为绝对路径)
2.sshd的key认证
1)生成密钥
[root@localhost ~]# ssh-keygen ##生成密钥的 命令
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ##指定保存加密的文件
Enter passphrase (empty for no passphrase): ##设定密码
Enter same passphrase again: ##私钥
Your identification has been saved in /root/.ssh/id_rsa. ##公钥
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
1a:14:3e:9b:78:8f:51:e9:80:3a:3c:3e:bd:4d:8f:b8 root@localhost
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| o . . |
| . = o |
| . . o B |
| = . * S |
| . + . * |
| o . + . |
| . = o |
| E.o . |
+-----------------+
2)加密服务
[root@localhost ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.70.150 ##加密root用户
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.25.70.150's password:Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@172.25.70.150'"
and check to make sure that only the key(s) you wanted were added.[root@localhost ~]# cd .ssh
[root@localhost .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts ##此文件出现表示加密成功
3)分发钥匙
[root@localhost .ssh]# scp /root/.ssh/id_rsa root@172.25.70.50:/root/.ssh/
The authenticity of host '172.25.70.50 (172.25.70.50)' can't be established.
ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.25.70.50' (ECDSA) to the list of known hosts.
root@172.25.70.50's password:
id_rsa
4)测试
[root@localhost ~]ssh root@172.25.70.250 ##连接时发现直接登陆
3.sshd的安全设定
Password
PasswdAuthentication yes ##是否允许用户通过密码做sshd认证
PermitRootLogin yes ##是否允许root用户通过sshd服务的认证
AllowUser student user ##设置用户白名单,白名单出现,默认不在白名单中的用户不能数用sshd
DenyUsers user ##设置用户黑名单,黑名单出现,默认不在白名单中的用户不能数用sshd
4.添加sshd登陆信息
vim /etc/motd ##文件内容的就是登陆后的信息显示
5.用户的登陆审计
1)
w ##查看正在使用当前系统的用户
w -f ##查看使用来源
w -i ##显示ip
2)
last ##查看使用过并退出的用户信息
3)
lastb ##试图登陆但没有成功的用户
6.文件在系统中的传输
1.scp
scp file root@ip:dir ##上传(dir为绝对路径)
scp root@ip:file dir ##下载(file为绝对路径)
2.rsync ##远程同步,速度快,默认会忽略文件属性,链接文件,设备文件
rsync -r ##同步目录
rsync -p ##同步权限
rsync -o ##同步文件所有人
rsync -g ##同步文件所有组
rsync -t ##同步文件事件戳
rsync -l ##同步链接文件
rsync -D ##同步设备文件
3.tar
tar -c ##创建
tar -x ##解档
tar -v ##显示过程
tar -f ##指定归档文件名称
tar -t ##查看归档文件内容
tar -r ##添加文件到归档中
tar --get ##解档指定文件
tar --delete ##删除归档中的指定文件
tar -C ##指定解档目录i
4.压缩与解压:
1)zip
zip -r xxx.tar xxx
zip -r xxx.tar.zip xxx.tar
unzip xxx.tar.zip
2)gz
gzip xxx.tar
gunzip xxx.tar.gz
============
tar zcf xxx.tar.gz /xxx
tar zxf xxx.tar.gz
3)bz2
bzip2 xxx.tar
bunzip2 xxx.tar.bz2
=============
tar jcf xxx.tar.bz2 /xxx
tar jxf xxx.tar.bz2
4)xz
xz xxx.tar
unxz xxx.tar.xz
=============
tar Jcf xxx.tar.xz /xxx
tar Jxf xxx.tar.xz