Linux操作系统入门(4)

进程的动态监控

1.top
1 显示cpu每个核的负载
s 调整书信频率
c cpu负载排序
m 内存使用量排序
h 查看帮助
u 查看指定用户进程
k 对指定进程发起信号
q 退出

控制服务

1.什么是服务

2.用什么控制服务
系统初始化进程可以对服务进行相应的控制

3.当前系统初始化进程是什么
systemd 系统初始化进程
pstree 显示系统中的进程树

4.进程控制命令
ssh—>sshd
client server

systemctl	        服务控制命令
systemctl status  sshd	查看服务状态,inactive(不可用),active(可用)
systemctl start   sshd	开启服务
systemctl stop	  sshd	关闭服务
systemctl restart sshd	重启服务
systemctl reload  sshd	重新加载服务配置
systemctl enable  sshd 	设定服务开机启动	
systemctl disable sshd 	设定服务开机不启动
systemctl list-units	列出已经开启服务的当前状态
systemctl list-dependencies	列出服务依赖
systemctl set-default multi-user.target 	设定系统启动级别为多用户模式(无图形)
systemctl set-default graphical.target   	设定系统启动级别为图形模式

sshd服务

1.sshd简介
sshd = secure shell
可以通过网络在主机中开启shell服务

客户端软件
ssh

连接方式:
ssh username@ip 文本模式的连接
ssh -X username@ip 可以在连接成功后打开图形

注意:
第一次连接陌生主机时需要建立认证文件
会询问是否建立,需要输入yes
再次连接此主机时。因为已经生成~/.ssh/know_hosts

远程复制:

scp	file	root@ip:dir 	上传(dir为绝对路径)
scp	root@ip:file      dir	下载(file为绝对路径)

scp -rp test	root@ip:dir	上传目录(dir为绝对路径)
scp -rp root@ip:test	dir	下载目录(test为绝对路径)

ssh的key认证

ssh-keygen	生成密钥的命令
[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:
 12:ee:e7:0b:db:bd:50:47:e9:64:08:67:99:0a:ea:86 root@localhost
 The key's randomart image is:
 +--[ RSA 2048]----+
 |        . oo     |
 |      .  +o. .   |
 |     ... .. =    |
 |    .. ..  =     |
 |   o  o S . o    |
 |  E o. . . .     |
 |   .  o o        |
 |       * o       |
 |      . +.o.     |
 +-----------------+

当出现上面的情况时说明密钥已经生成

[root@localhost .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
 The authenticity of host '172.25.254.209 (172.25.254.209)' can't be established.
 ECDSA key fingerprint is 65:4d:ac:8a:c9:58:82:b5:0c:91:c4:ef:a5:e6:f6:65.
 Are you sure you want to continue connecting (yes/no)? yes
 /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
 [email protected]'s password: 

 Number of key(s) added: 1

 Now try logging into the machine, with:   "ssh '[email protected]'"
 and check to make sure that only the key(s) you wanted were added.

 [root@localhost .ssh]# ls 
 authorized_keys  id_rsa  id_rsa.pub  known_hosts
 当出现第一个文件时说明加密成功

分发钥匙

 **scp /root/.ssh/id_rsa [email protected]:/root/.ssh/**

测试
在客户主机中(172.25.254.209)

ssh [email protected]
连接时发现直接登录不需要密码

ssd的安全设定

 PasswordAuthentication yes		是否允许用户通过密码做sshd认证
 PermitRootLogin yes			是否允许root用户通过sshd服务的认证
 AllowUsers student westos		设定用户白名单,白名单出现,默认不在白名单的用户不能使用sshd
 DenyUsers westos			设定用户黑名单,黑名单出现,默认不在黑名单的用户可以使用sshd

添加sshd登录信息

 vim /etc/motd				文件内容就是登陆后的信息显示

用户登录审计

1.w 查看正在正在使用当前系统的用户
-f 查看使用来源
-i 显示IP
在这里插入图片描述
2last 查看使用过并退出的用户信息
在这里插入图片描述

3.lastb 试图登录但没成功的用户
在这里插入图片描述

文件在系统中传输

scp:

scp	file	root@ip:dir 	上传(dir为绝对路径)
scp	root@ip:file dir	下载(file为绝对路径)

scp -rp test	root@ip:dir	上传目录(dir为绝对路径)
scp -rp root@ip:test	dir	下载目录(test为绝对路径)

rsync
远程同步,速度快,默认会忽略文件属性,链接文件,设备文件
-r 同步目录
-p 同步权限
-o 同步文件所有人
-g 同步文件所有组
-t 同步时间
-l 同步链接文件
-D 同步设备文件
tar
-c 创建
-x 解档
-v 显示过程
-f 指定归档文件名称
-t 查看归档文件内容
-r 添加文件到归档中
–get 解档指定文件
–delete 删除归档中的指定文件
-C 指定解档目录

压缩

zip
zip -r  xxx.tar.zip	xxx.tar
unzip	xxx.tar.zip

gz
gzip	xxx.tar
gunzip	xxx.tar.gz
===
tar zcf xxx.tar.gz
tar zxf	xxx.tar.gz

bz2
bzip2	xxx.tar
bunzip2	xxx.tar.bz2
===
tar jcf xxx.tar.bz2 /xxx
tar jxf xxx.tar.bz2

xz	
xz	xxx.tar
unxz	xxx.tar.xz
===
tar Jcf xxx.tar.xz /xxx
tar Jxf xxx.tar.xz	

查看了压缩文件的大小并解压
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_37206112/article/details/82931830