随堂笔记

一、cup

1.1查看cpu

lscpu

#查看cpu
[root@c002 ~ 09:55:24]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
座:                 1
NUMA 节点:         1
厂商 ID:           AuthenticAMD
CPU 系列:          25
型号:              80
型号名称:        AMD Ryzen 9 5900HX with Radeon Graphics
步进:              0
CPU MHz:             3293.814
BogoMIPS:            6587.62
超管理器厂商:  VMware
虚拟化类型:     完全
L1d 缓存:          32K
L1i 缓存:          32K
L2 缓存:           512K
L3 缓存:           16384K
NUMA 节点0 CPU:    0
#重点查看一下内容
#CPU(s):                1
#型号名称:        AMD Ryzen 9 5900HX with Radeon Graphics
#CPU MHz:             3293.814

1.2给cpu加负载

md5sum /dev/zero &

[root@c002 ~ 10:06:08]# md5sum /dev/zero &
[1] 47696 

2.1查看使用情况

top

[root@c002 ~ 10:10:46]# top
top - 10:12:45 up 53 min,  2 users,  load average: 1.19, 0.52, 0.24
Tasks: 350 total,   3 running, 347 sleeping,   0 stopped,   0 zombie
%Cpu(s): 95.0 us,  5.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   1003432 total,   308416 used,   695016 free,      764 buffers
KiB Swap:  2097148 total,        0 used,  2097148 free.   148680 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                    
 47696 root      20   0  108072    620    524 R 97.8  0.1   2:16.74 md5sum           
  2088 root      20   0  133836   5468   4088 S  0.3  0.5   0:09.25 sshd             
     1 root      20   0   50852   7180   2524 S  0.0  0.7   0:00.85 systemd           
     2 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kthreadd         
     3 root      20   0       0      0      0 S  0.0  0.0   0:00.01 ksoftirqd/0       
     5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H          6 root      20   0       0      0      0 S  0.0  0.0   0:00.33 kworker/u256:0   
     7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0       
     8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh           
     9 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/0           
    10 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/1           
    11 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/2           
    12 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/3           
    13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/4               14 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/5           
    15 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/6           
    16 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/7           
    17 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/8          
    18 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/9               19 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/10             20 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/11

查看使用情况 top 命令

使用P (cpu降序排序)

使用M (内存降序排序)

2.2cpu指标

%Cpu(s): 95.0 us,  5.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
#%Cpu(s): 95.0 us(user用户),  5.0 sy(system系统)

二、内存指标

free -m

查看cpu时可以看到内存的情况

KiB Mem:   1003432 total,   308416 used,   695016 free,      764 buffers

三、磁盘

3.1磁盘容量查看

df -h

[root@c002 ~ 10:12:46]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   18G  4.3G   14G   25% /
devtmpfs                 484M     0  484M    0% /dev
tmpfs                    490M     0  490M    0% /dev/shm
tmpfs                    490M  6.7M  484M    2% /run
tmpfs                    490M     0  490M    0% /sys/fs/cgroup
/dev/sda1                497M   96M  401M   20% /boot

3.2 硬盘速度

模拟下载

iotop可以查看每个进程

#下载文件
[root@c002~10:24:06]#wgethttp://192.168.42.100/02.%E7%B3%BB%E7%BB%9F%E9%95%9C%E5%83%8F/CentOS-7-x86_64-DVD-2207-02.iso

#再开一台虚拟机,查看下载时的硬盘速度
[root@c002 ~ 10:27:12]# iotop
Total DISK READ :       0.00 B/s | Total DISK WRITE :      42.98 M/s
Actual DISK READ:     946.23 K/s | Actual DISK WRITE:      95.80 K/s
   TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                        
 42898 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.19 % [kworker/0:2]
   810 be/3 root        0.00 B/s   15.64 K/s  0.00 %  0.00 % auditd -n
 60729 be/4 root        0.00 B/s   42.97 M/s  0.00 %  0.00 % wget http://192.~4-DVD-2207-02.iso
     1 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % systemd --switch~ --deserialize 23
     2 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kthreadd]
     3 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/0]
     5 be/0 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/0:0H]
     6 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kworker/u256:0]
     7 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [migration/0]
     8 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcu_bh]
     9 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/0]
    10 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/1]
    11 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/2]
    12 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/3]
    13 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/4]
    14 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/5]
    15 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/6]
    16 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/7]
    17 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/8]
    18 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/9]
    19 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/10]
    20 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/11]
    21 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/12]
    22 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/13]
    23 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [rcuob/14]

iotop可以查看每个进程,可以排序

硬盘名称:sda 第一块sata接口硬盘 再往后就是sdb…sdc…

3.3 查看指定硬盘的读写速度

sar -dp 1

[root@c002 ~ 10:33:53]# sar -dp 1
Linux 3.10.0-123.el7.x86_64 (c002)      2026年04月02日  _x86_64_        (1 CPU)
10时36分17秒       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
10时36分18秒       sda      3.00      0.00     35.00     11.67      0.00      0.00      0.00      0.00
10时36分18秒       sr0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
10时36分18秒 centos-swap      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
10时36分18秒 centos-root      3.00      0.00     35.00     11.67      0.00      0.00      0.00      0.00
10时36分18秒       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
10时36分19秒       sda      7.07     56.57     18.18     10.57      0.00      0.14      0.14      0.10
10时36分19秒       sr0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
10时36分19秒 centos-swap      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
10时36分19秒 centos-root      7.07     56.57     18.18     10.57      0.00      0.14      0.14      0.10

单位是 k rd_sec/s(读) wr_sec/s(写)

3.4关闭进程

[root@c002 ~ 10:43:30]# top
top - 10:43:39 up  1:24,  4 users,  load average: 1.55, 1.72, 1.49
Tasks: 356 total,   4 running, 352 sleeping,   0 stopped,   0 zombie
%Cpu(s): 93.8 us,  6.2 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   1003432 total,   892332 used,   111100 free,        0 buffers
KiB Swap:  2097148 total,     2424 used,  2094724 free.   708280 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                    
 47696 root      20   0  108072    576    480 R 99.9  0.1  31:54.48 md5sum           
     1 root      20   0   50988   6860   2128 S  0.0  0.7   0:00.95 systemd           
     2 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kthreadd         
     3 root      20   0       0      0      0 S  0.0  0.0   0:00.03 ksoftirqd/0       
     5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H     
     7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0       
     8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh           
     9 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/0           
    10 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/1           
    11 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/2           
    12 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/3           
    13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/4           
    14 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/5           
    15 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/6           
    16 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/7           
    17 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/8           
    18 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/9           
    19 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/10         
    20 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/11         
    21 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/12         
    22 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/13         
[root@c002 ~ 10:43:42]# kill 47696
[root@c002 ~ 10:44:08]# top
top - 10:44:35 up  1:25,  4 users,  load average: 1.07, 1.58, 1.45
Tasks: 355 total,   2 running, 353 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.3 us,  3.3 sy,  0.0 ni, 95.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   1003432 total,   891960 used,   111472 free,        0 buffers
KiB Swap:  2097148 total,     2424 used,  2094724 free.   708580 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND           
  2088 root      20   0  133836   4064   2684 S  0.3  0.4   0:14.78 sshd             
  2174 root      20   0  124620   2364   1092 S  0.3  0.2   0:07.09 top               
 61083 root      20   0  133816   4040   2684 S  0.3  0.4   0:03.13 sshd             
 61216 root      20   0  124624   2380   1096 S  0.3  0.2   0:01.44 top               
 88321 root      20   0       0      0      0 S  0.3  0.0   0:00.03 kworker/0:3       
     2 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kthreadd         
     3 root      20   0       0      0      0 S  0.0  0.0   0:00.03 ksoftirqd/0       
     5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H     
     7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0       
     8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh           
     9 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/0           
    10 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/1           
    11 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/2           
    12 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/3           
    13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/4           
    14 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/5           
    15 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/6           
    16 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/7          
    17 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/8           
    18 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/9   
查看网卡
[zhusheng@c002 ~ 09:17:09]$ sar -n DEV 1
Linux 3.10.0-123.el7.x86_64 (c002) 	2026年04月03日 	_x86_64_	(1 CPU)

09时18分55秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
09时18分56秒 eno16777736      1.98      0.99      0.12      0.18      0.00      0.00      0.00
09时18分56秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

09时18分56秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
09时18分57秒 eno16777736      1.00      1.00      0.06      0.40      0.00      0.00      0.00
09时18分57秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

09时18分57秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
09时18分58秒 eno16777736      1.01      1.01      0.06      0.40      0.00      0.00      0.00
09时18分58秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
^
09时18分58秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
09时18分59秒 eno16777736      3.00      2.00      0.22      0.50      0.00      0.00      0.00
09时18分59秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

09时18分59秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
09时19分00秒 eno16777736      1.00      1.00      0.06      0.40      0.00      0.00      0.00
09时19分00秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
^V
09时19分00秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
09时19分01秒 eno16777736      6.00      4.00      0.44      0.62      0.00      0.00      0.00
09时19分01秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

四、服务管理

4.1 systemd

pid为1的程序是systemd,也是系统的第一个进程,负责操作系统整个资源的管理。

系统中服务也是由systemd管理。

命令:systemctl action service-name

action : status(状态) start(开始) stop(临时关闭) restart(重启)

​ enable(开机自动启动)disable(开机不自启动)

​ is-active(查看是否启动)is-enabled(查看是否开机自动启动)

service-name : sshd firewalld mysqld

systemd 与 systemctl 关系:

​ 1.systemd 一直运行的程序

​ 2.systemctl 是给systemd下指令的工具,人与机器之间交互使用

类比于web服务器:

1.http

2.浏览器访问页面去访问http

4.2查看服务

[root@c002 ~ 11:20:31]# systemctl status sshd
sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
   Active: active (running) since 四 2026-04-02 09:18:58 CST; 2h 1min ago
 Main PID: 1097 (sshd)
   CGroup: /system.slice/sshd.service
           └─1097 /usr/sbin/sshd -D
####运行记录####
4月 02 09:18:58 c002 systemd[1]: Started OpenSSH server daemon.
4月 02 09:18:58 c002 sshd[1097]: Server listening on 0.0.0.0 port 22.
4月 02 09:18:58 c002 sshd[1097]: Server listening on :: port 22.
4月 02 09:19:12 c002 sshd[2088]: Accepted password for root from 192.168.100.1 port 65053 ssh2
4月 02 10:26:58 c002 sshd[61083]: Accepted password for root from 192.168.100.1 port 511...sh2
Hint: Some lines were ellipsized, use -l to show in full.

####重点关注:Active: active (running)####

重点关注

Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
1、 配置文件位置 /usr/lib/systemd/system/sshd.service
第一个enable 代表开机自动启动
第二个enable 暂不关注

2、Active: active (running) 说明程序正在运行的状态

4.3停止服务

##把sshd停止
[root@c002 ~ 11:20:46]# systemctl stop sshd
##查看sshd的状态
[root@c002 ~ 11:26:06]# systemctl is-active sshd
inactive
##查看sshd的状态
[root@c002 ~ 11:26:29]# systemctl status sshd
sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
   Active: inactive (dead) since 四 2026-04-02 11:26:06 CST; 44s ago
 Main PID: 1097 (code=exited, status=0/SUCCESS)
#注意显示的内容提示:Active: inactive (dead)

4.4开启服务

##开启sshd服务
[root@c002 ~ 11:29:12]# systemctl start sshd
##查看sshd的开关状态
[root@c002 ~ 11:29:19]# systemctl is-active sshd
active

4.5取消开机自动启动

##关闭开启自动启动
[root@c002 ~ 11:35:31]# systemctl disable sshd
rm '/etc/systemd/system/multi-user.target.wants/sshd.service'
##查看自动开启的状态有没有关闭
[root@c002 ~ 11:36:10]# systemctl is-enabled sshd
disabled

4.6重启验证,试试机器是否能登录到终端工具(不能)

[root@c002 ~ 11:36:51]# reboot

连接断开
###不能登录到终端工具

4.7设置sshd服务开机启动

需要到虚拟机里面进入终端打开

##进入虚拟机终端输入命令
[root@centos7 ~ 11:04:12]# systemctl enable sshd
##查看是否开启开机启动成功
[root@centos7 ~ 11:04:55]# systemctl is-enabled sshd
enabled

4.8重启终端工具,看看是否能登入

连接主机...
连接主机成功
Last login: Thu Apr  2 11:41:59 2026
[root@c002 ~ 11:47:15]# 

五、开发服务

  1. 准备服务程序 /usr/local/bin/study

    [root@c001 ~ 17:12:04]# vim /usr/bin/study
    

    下面是代码内容,插入到study文件里面

    #!/bin/bash
    # 第一行内容是脚本的 "解释器声明"(shebang),指定该脚本使用 /bin/bash 
    作为解释器执行。系统会根据这一行找到对应的 shell 程序来解析后续命令。
    # 启动一个无限循环:while 是循环关键字,true 是一个永远为真的条件,因此
    这个循环会一直执行下去,直到被外部终止(如 Ctrl+C)。
    while true
    # 循环体的开始标记,do 和后面的 done 之间的内容是循环中重复执行的命令。
    do
      
      # 执行 date 命令(获取当前系统时间),并通过 $(...) 捕获其输出,将结果
    赋值给变量 DATE。
      DATE=$(date)
      
      # echo 命令输出字符串,其中 $DATE 会被替换为变量的值
      # >> 是追加重定向符号,将输出内容追加到 /var/log/study.log 文件中
      # 最终输出内容类似 Fri Oct 31 10:00:00 CST 2025: I'M studying [ 
    Linux ]echo "$DATE: I'M studying [ Linux ]" >> /var/log/study.log
      
      # 让脚本暂停执行 5 秒(sleep 命令用于延迟,单位默认为秒),避免循环执
    行过快。
      sleep 5
    # 循环体的结束标记,与前面的 while 和 do 配合,标志着一次循环的结束。
    done
    

    修改文件的权限,设置为可执行x

    [root@c001 ~ 17:13:20]# chmod +x /usr/bin/study
    
  2. 准备服务配置文件 /etc/systemd/system/studyd.service

    程序后面的d,daemon,守护称呼

    [root@c001 ~ 17:16:53]# cp /usr/lib/systemd/system/sshd.service /etc/systemd/system/studyd.service
    [root@c001 ~ 17:28:03]# vim /etc/systemd/system/studyd.service 
    

    ![外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=C%3A%2FUsers%2F33783%2FDesktop%2Fphone%2Fimage-20260402172828600.png&pos_id=img-F2ikIwQC-177520595858
    ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/e8c29a4c0ce84449b6331eaa3690d7e3.png#pic_center

  3. 通知systemd 变化 systemctl daemon-reload

    #刷新
    [root@c001 ~ 17:29:24]# systemctl daemon-reload
    #开启开机自启
    [root@c001 ~ 17:30:11]# systemctl enable studyd
    ln -s '/etc/systemd/system/studyd.service' '/etc/systemd/system/multi-user.target.wants/studyd.service'
    [root@c001 ~ 17:35:15]# systemctl start studyd
    [root@c001 ~ 17:35:36]# systemctl is-active studyd
    active
    [root@c001 ~ 17:36:13]# tail -f /var/log/study.log
    2026年 04月 02日 星期四 17:35:51 CST: I'M studying [ Linux ]
    2026年 04月 02日 星期四 17:35:56 CST: I'M studying [ Linux ]
    2026年 04月 02日 星期四 17:36:01 CST: I'M studying [ Linux ]
    2026年 04月 02日 星期四 17:36:06 CST: I'M studying [ Linux ]
    2026年 04月 02日 星期四 17:36:11 CST: I'M studying [ Linux ]
    2026年 04月 02日 星期四 17:36:16 CST: I'M studying [ Linux ]
    2026年 04月 02日 星期四 17:36:21 CST: I'M studying [ Linux ]
    2026年 04月 02日 星期四 17:36:26 CST: I'M studying [ Linux ]
    2026年 04月 02日 星期四 17:36:31 CST: I'M studying [ Linux ]
    2026年 04月 02日 星期四 17:36:36 CST: I'M studying [ Linux ]
    2026年 04月 02日 星期四 17:36:41 CST: I'M studying [ Linux ]
    
  4. 激活服务 systemctl enable studyd --now

[root@c001 ~ 17:30:11]# systemctl enable studyd
ln -s '/etc/systemd/system/studyd.service' '/etc/systemd/system/multi-user.target.wants/studyd.service'

六、ssh 工具使用

6.1windows中使用普通命令行操作:

ssh root@10.1.8.10或者ssh laoma@10.1.8.10

#ssh root@192.168.100.102
C:\Users\33783>ssh root@192.168.100.102
root@192.168.100.102's password:
Last login: Thu Apr  2 16:42:42 2026 from 192.168.100.1
[root@c002 ~ 17:39:24]# exit
登出
Connection to 192.168.100.102 closed.
#ssh zhusheng@192.168.100.102
C:\Users\33783>ssh zhusheng@192.168.100.102
zhusheng@192.168.100.102's password:
Last login: Thu Apr  2 16:10:41 2026
[zhusheng@c002 ~ 17:39:50]$ exit
登出
Connection to 192.168.100.102 closed.
C:\Users\33783>

ssh laoma@10.1.8.10 hostname

C:\Users\33783>ssh zhusheng@192.168.100.102 hostname
zhusheng@192.168.100.102's password:
c002

ssh laoma@10.1.8.10 id

C:\Users\33783>ssh zhusheng@192.168.100.102 id
zhusheng@192.168.100.102's password:
uid=1001(zhusheng) gid=1001(zhusheng)=1001(zhusheng) 环境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

6.2为自己创建一个普通 用户,并设置密码

[root@c001 ~ 17:36:42]# useradd zhusheng
[root@c001 ~ 17:59:39]# passwd zhusheng
更改用户 zhusheng 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

[root@c001 ~ 17:59:55]# useradd zhu
[root@c001 ~ 18:00:13]# echo 123456 | passwd --stdin zhu
更改用户 zhu 的密码 。
passwd:所有的身份验证令牌已经成功更新。

6.3切换默认用户,不需要提示

6.3.1准备配置文件
[root@c001 ~ 18:06:49]# cp /ect/ssh/ssh_config .ssh/config
cp: 无法获取"/ect/ssh/ssh_config" 的文件状态(stat): 没有那个文件或目录
#如果没有这个文件,可以用下面的命令实现出来
[root@c001 ~ 18:07:30]# ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is 74:81:95:07:ca:3d:93:dd:f8:36:c8:e3:e2:1b:6e:35.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
root@localhost's password: 
Last login: Thu Apr  2 17:08:40 2026 from 192.168.100.1
[root@c001 ~ 18:08:06]# cp /etc/ssh/ssh_config .ssh/config
[root@c001 ~ 18:08:41]# vim .ssh/config 
#文件里面的修改如下

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

删除前19行

取消相应行注释 把ask(提示信息)改为 no(不提示)

新增 User 行:指明默认登录用户 User root

6.3.2验证
[root@c002 ~ 17:55:52]# su - zhusheng
上一次登录:四 42 17:39:50 CST 2026192.168.100.1pts/1 上
[zhusheng@c002 ~ 17:55:57]$ ssh 192.168.100.102
root@192.168.100.102's password: 
Last login: Thu Apr  2 17:55:45 2026 from c001

6.4 ssh命令行传递密码工具 sshpass

[zhusheng@c002 ~ 18:03:33]$ sshpass -p 123456 ssh root@192.168.100.102
Last login: Thu Apr  2 18:03:07 2026 from c002
[root@c002 ~ 18:04:07]# 

七、vim操作

  1. :set nu 显示行号

  2. :3,5d 【或者 光标移动到第三行d3d】 删除3-5行

  3. :5,6d 删除5-6行

  4. :6,9d 删除6-9行

  5. /字符串 搜索并定位到特定字符串位置

  6. cw (change word)替换一个单词(自动进入插入模式)

  7. C(删除到最后,并进入插入模式)

  8. ZZ 保存退出。

八、分析sshd建立连接流程

  1. windows 管理员身份打开cmd,执行arp -d 192.168.100.101(自己Linux服务IP)
  2. 开启wireshark,捕捉vmware 8 nat网卡流量
  3. 使用终端登录 Linux 服务
  4. 分析 抓包结果

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

sshd对应OSI 七层模型的表示层

``

6.4 ssh命令行传递密码工具 sshpass

[zhusheng@c002 ~ 18:03:33]$ sshpass -p 123456 ssh root@192.168.100.102
Last login: Thu Apr  2 18:03:07 2026 from c002
[root@c002 ~ 18:04:07]# 

七、vim操作

  1. :set nu 显示行号

  2. :3,5d 【或者 光标移动到第三行d3d】 删除3-5行

  3. :5,6d 删除5-6行

  4. :6,9d 删除6-9行

  5. /字符串 搜索并定位到特定字符串位置

  6. cw (change word)替换一个单词(自动进入插入模式)

  7. C(删除到最后,并进入插入模式)

  8. ZZ 保存退出。

八、分析sshd建立连接流程

  1. windows 管理员身份打开cmd,执行arp -d 192.168.100.101(自己Linux服务IP)
  2. 开启wireshark,捕捉vmware 8 nat网卡流量
  3. 使用终端登录 Linux 服务
  4. 分析 抓包结果

[外链图片转存中…(img-PxcD0Fi6-1775205958582)]

sshd对应OSI 七层模型的表示层

Logo

openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构

更多推荐