[toc]

安全控制

一.重置root密码

Centos7 与之前的版本不同,当忘记 root 密码,并采用 GRUB2 为启动器时,将无法通过单用户模式重 置 root 密码

1
# 1.启动系统,并在GRUB2启动屏显时,按下 e 键进入编辑模式

image-20220525143741425

1
# 2.按e后,看到如下画面:

image-20220525143824081

1
# 3.找到 linux16 开头的行,按 end 键跳转到最后,空格后,输入 rd.break

image-20220525144314955

1
# 4.按 ctrl+x 进入紧急救援模式

image-20220525144530907

1
2
3
4
5
6
7
8
9
10
11
12
# 5.重新挂载系统分区,输入
mount -o remount,rw /sysroot
# 6.再输入
chroot /sysroot
# 改变根
# 7.当前目录变为根目录,即可更改密码
echo 123456 | passwd --stdin root
# 8.如果之前系统启用了 SElinux,则必须运行
touch /.autorelabel
否则将无法正常启动系统
# 9.输入 exit 退出
# 10.输入 reboot 重新启动

image-20220525145647885

1
# 登录测试,密码123456更新成功

image-20220525150014292

二.强密码修改安全性

矛与盾

方法一

  • 为 GRUB2 菜单加上防编辑密码,以防止恶意者像如上一样修改 root 密码
1
2
3
4
5
# 1.用 grub2-mkpasswd-pbkdf2 命令生成加密口令
[root@localhost ~]# grub2-mkpasswd-pbkdf2
输入口令: # 不是root密码
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.D167D00E2EB2403C60A1F73D67E8E09ED1D0BD871ECC04D15AC815C9E1FCC178D4BC2B05FA4A1DEA67FBC1DD29CEF48EF662E1D5DB8C16AAB4F27FC353815FF5.43D49742A39635DE65BF5631802EB4041E38E65A05AB8AD6F498538873FA241599DE784CE0CF63E4E3FE68DC0FE635251A74EBC53C62239480AE558D68BA77D3

然后

1
2
3
4
5
6
[root@localhost ~]# vim /etc/grub.d/00_header 
# 在最后位置写入这个脚本命令
cat <<EOF
set superusers="root" # 这个是账号,可以随心填,但是要记住它和上面的密码
password_pbkdf2 root grub.pbkdf2.sha512.10000.D167D00E2EB2403C60A1F73D67E8E09ED1D0BD871ECC04D15AC815C9E1FCC178D4BC2B05FA4A1DEA67FBC1DD29CEF48EF662E1D5DB8C16AAB4F27FC353815FF5.43D49742A39635DE65BF5631802EB4041E38E65A05AB8AD6F498538873FA241599DE784CE0CF63E4E3FE68DC0FE635251A74EBC53C62239480AE558D68BA77D3
EOF

重新生成grub2

1
2
3
4
5
6
7
8
9
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg 
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1160.66.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.66.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-dbecb3d028cd4f5db6753a52b01ffd86
Found initrd image: /boot/initramfs-0-rescue-dbecb3d028cd4f5db6753a52b01ffd86.img
done

方法二

1
2
3
4
[root@localhost ~]# vim /boot/grub2/grub.cfg
set superusers="root"
password_pbkdf2 root grub.pbkdf2.sha512.10000.D167D00E2EB2403C60A1F73D67E8E09ED1D0BD871ECC04D15AC815C9E1FCC178D4BC2B05FA4A1DEA67FBC1DD29CEF48EF662E1D5DB8C16AAB4F27FC353815FF5.43D49742A39635DE65BF5631802EB4041E38E65A05AB8AD6F498538873FA241599DE784CE0CF63E4E3FE68DC0FE635251A74EBC53C62239480AE558D68BA77D3
### END /etc/grub.d/00_header # 在这个文件上面写入以上参数,也可以达到一样效果。。。我是傻x

进入grub2

1
# 再次进入 GRUB2 页面,发现需要输入账户名与密码

image-20220525155917825

image-20220525155936054

image-20220525160014769

三.破坏MBR

  • MBR

    • master boot record
    • 主引导记录,也叫主引导扇区
    • 硬盘的 0 柱面,0 磁头,1 扇区称为主引导扇区
    • 其中 446 Byte 是 bootloader,64 Byte 是 partition table,剩下的 2 Byte 是 magic number
    • 一般破坏的是bootloader

    Linux是文件型的操作系统,所有的信息和数据都以文件形式保存于系统中,但是并不是所有的数据,主 引导记录就不是以文件的形式保存,无法进行备份,只能通过 dd 命令备份

  • 先进行备份,再破坏

    • 使用 dd 命令,将 sda 的 MBR 进行备份
    • 用 zero设备生成 446 字节的 “0” 写入 MBR
    • 重启后发现系统已坏
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[root@localhost ~]# fdisk -l

磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b88c2

设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 209715199 103808000 8e Linux LVM

磁盘 /dev/mapper/centos-root:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:4160 MB, 4160749568 字节,8126464 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-home:48.4 GB, 48444211200 字节,94617600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@localhost ~]# dd if=/dev/sda of=/root/mbr.bak count=1 bs=512
记录了1+0 的读入
记录了1+0 的写出
512字节(512 B)已复制,0.000344858 秒,1.5 MB/秒
[root@localhost ~]# dd if=/dev/zero of=/dev/sda count=1 bs=446
记录了1+0 的读入
记录了1+0 的写出
446字节(446 B)已复制,0.000186601 秒,2.4 MB/秒

  • if=/dev/sda
    • interface 输入接口
  • of=/root/mbr.bak
    • outerface 输出接口
  • count=1
    • 写一块
  • bs=512
    • 将整个扇区选中

  • Unix/Linux将每一个设备都当成一个文件,放在/dev目录

    • 这些文件有的对应着一个真实存在的物理设备

    • 有的则代表一个虚拟设备,提供一些特定的功能

  • /dev/null

    • “空”设备,也有人称它为黑洞

    • 任何输入到这个“设备”的数据都将被直接丢弃

    • 最常用的用法是把不需要的输出重定向到这个文件

  • /dev/zero

    • “零”设备,可以无限的提供空字符(0x00,ASCII代码NUL)

    • 常用来生成一个特定大小的文件

1
[root@localhost ~]# dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress #创建4G的交换空间 大小根据需要自定

这也是我喜欢用交换文件而不是交换分区的一个特点之一_方便

四.修复MBR

1
2
[root@localhost ~]# reboot
# 重启后,发现无法正常启动

image-20220525174104226

  • 连接光盘,重启后进入系统安装光盘,在光盘引导界面选择 Troubleshooting

image-20220525190633165

  • 选择救援模式 Rescue a Centos system

image-20220525190612467

  • 输入1,选择Continue,以 rw 模式挂载分区

image-20220525190742957

  • 回车,进入救援模式

image-20220525190905564

  • grub2-install 命令重建 Bootloader,随后 sync 写入硬盘,reboot 重启系统
1
2
3
4
5
sh-4.2# chroot /mnt/sysimage
sh-4.2# grub2-install /dev/sda
sh-4.2# sync
sh-4.2# exit
sh-4.2# reboot
  • 重启后,可正常进入开机引导

image-20220525191143114

五. 修复GRUB

**若grub配置文件丢失,开机会直接进入 grub 界面,显示为 grub> **

由于 grub2 的文件极其复杂,所以一定要做好备份

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[root@localhost ~]# fdisk -l

磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x00000000

设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 209715199 103808000 8e Linux LVM

磁盘 /dev/mapper/centos-root:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:4160 MB, 4160749568 字节,8126464 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-home:48.4 GB, 48444211200 字节,94617600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
└─centos-home 253:2 0 45.1G 0 lvm /home
sr0 11:0 1 4.4G 0 rom /run/media/root/CentOS 7 x86_64

1
2
3
4
5
6
7
8
9
10
# 先备份,再破坏
[root@localhost ~]# mkdir grub2.bak
[root@localhost ~]# chmod 600 grub2.bak/
[root@localhost ~]# cp -rp /boot/grub2/* ./grub2.bak/
[root@localhost ~]# ls grub2.bak/
device.map fonts grub.cfg grubenv i386-pc locale
# 破坏
[root@localhost ~]# rm /boot/grub2/grub.cfg
rm:是否删除普通文件 "/boot/grub2/grub.cfg"?y
[root@localhost ~]# reboot

image-20220525191903755

  • 重启后,进入 “ grub> ” 状态,输入以下命令设置启动参数
1
2
3
4
5
6
7
8
9
grub> insmod xfs
# 第0块磁盘的第1个分区
grub> set root='hd0,1'
# 内核文件
# mapper是逻辑卷组
grub> linux16 /vmlinuz-3.10.0-229.el7.x86_64
root=/dev/mapper/centos-root
grub> initrd16 /initramfs-3.10.0-229.el7.x86_64.img
grub> boot

恢复grub

1
2
[root@localhost ~]# cp ./grub2.bak/grub.cfg /boot/grub2/
[root@localhost ~]# reboot

[toc]

ssh反代问题

问题一

问题一.我有A和B两台服务器,一台在学校ip是10.71.10.25,另外一台在印度ip是124.156.xx.xx,现在我想构建ssh反向代理,让我的服务器A能被外网ssh连接,防止我不在校园也能控制服务器A。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 服务器A设置
root@raspbian:/configuration/script# vim ssh_reverse_proxy.sh
#!/bin/bash
ssh -fN -R 8101:localhost:22 root@124.156.xx.xx

# 监控程序脚本
root@raspbian:/configuration/script# vim ssh_reverse_proxy_daemon.sh
#!/bin/bash
while true;do

Flag=`ps -ef | grep "8101" | grep -v "grep"`

if [ -z "$Flag" ]; then

echo "restart ssh server"
bash /configuration/script/ssh_reverse_proxy.sh
# ssh -fN -R 8101:localhost:22 root@124.156.xx.xx
fi

sleep 100

done


# 加入reboot开机自启计划
root@raspbian:/configuration/script# crontab -e
@reboot /configuration/script/ssh_reverse_proxy.sh
@reboot /configuration/script/ssh_reverse_proxy_daemon.sh


# 两台服务器相互交换公钥到对方的/.ssh/authorized_keys,并且把自己的公钥加入到自己的/.ssh/authorized_keys

服务器互联目前不需要密码
脚本程序一切正常,但是服务器A只有重启后的几分钟内能够用服务器B连接,时间长点的话,比如:30分钟后,会发现服务器B一直连接不上

附图(一下三种情况都是在A服务器发出脚本,并且正常运行的到的):

情况一:(连得上)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
服务器A
root@raspbian:/configuration/script# ps -ef | grep 8101 | grep -v "grep"
root 21390 1 0 11:27 ? 00:00:00 ssh -fN -R 8101:localhost:22 root@124.156.xx.xx

服务器B
[root@VM-0-17-centos ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 52:54:00:46:11:0d brd ff:ff:ff:ff:ff:ff
inet 10.0.0.17/20 brd 10.0.15.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe46:110d/64 scope link
valid_lft forever preferred_lft forever
[root@VM-0-17-centos ~]# ssh localhost -p 8101
Linux raspbian 5.10.78-Release-OPENFANS+20211111-v8 #1 SMP PREEMPT Thu Nov 11 15:43:52 CST 2021 aarch64

This system Debian Pi Aarch64 for Raspberry Pi 3B/3B+/3A+/4B,
Created by OPENFANS.ORG & PIFAN.ORG .

Your can visit our official site:
http://www.openfans.org & http://www.pifan.org

Project address:
https://github.com/openfans-community-offical/Debian-Pi-Aarch64

It is strictly prohibited for any commercial use
without permission!

Especially some disgusting Taobao merchants,
congratulations to being warned!

Activate the web console with: systemctl enable --now cockpit.socket

You have new mail.
Last login: Tue May 31 11:10:02 2022 from 10.71.5.50

.~~. .~~. ___ __ ___ _
'. \ ' ' / .' / _ \___ ___ ___ / / ___ ___ ___ _ __ / _ \(_)
.~ .~~~..~. / , _/ _ `(_-</ _ \/ _ \/ -_) __/ __/ // / / ___/ /
: .~.'~'.~. : /_/|_|\_,_/___/ .__/_.__/\__/_/ /_/ \_, / /_/ /_/
~ ( ) ( ) ~ /_/ /___/
( : '~'.~.'~' : )
~ .~ ( ) ~. ~ Copyright (c) 2017-2022, OPENFANS.ORG & PIFAN.ORG
( : '~' : ) Linux Version 5.10.78-Release-OPENFANS+2021111
'~ .~~~. ~' Compiled #1 SMP PREEMPT Thu Nov 11 15:43:52 CST 2021
'~' Four ARM Processors, 7.9GB RAM
432.00 Bogomips Total
root@raspbian:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether e4:5f:01:3d:b7:4f brd ff:ff:ff:ff:ff:ff
inet 10.71.10.159/24 brd 10.71.10.255 scope global dynamic noprefixroute eth0
valid_lft 133302sec preferred_lft 133302sec
inet6 fe80::c2b7:8023:6697:581f/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq state DOWN group default qlen 1000
link/ether e4:5f:01:3d:b7:50 brd ff:ff:ff:ff:ff:ff
4: macvlan@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 1a:55:9c:25:a7:5b brd ff:ff:ff:ff:ff:ff
inet 10.71.10.25/24 brd 10.71.10.255 scope global macvlan
valid_lft forever preferred_lft forever
inet6 fe80::1855:9cff:fe25:a75b/64 scope link
valid_lft forever preferred_lft forever
5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:5b:34:04:4f brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:5bff:fe34:44f/64 scope link
valid_lft forever preferred_lft forever
6: br-6f69248df895: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:f3:c1:54:d1 brd ff:ff:ff:ff:ff:ff
inet 172.18.0.1/16 brd 172.18.255.255 scope global br-6f69248df895
valid_lft forever preferred_lft forever
9: vetha11c56c@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 42:0f:dc:8a:33:57 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::400f:dcff:fe8a:3357/64 scope link
valid_lft forever preferred_lft forever
# 已经连上

情况二:(连不上,但是一直尝试连接,没有报错)

1
2
3
4
5
6
7
8
9
[root@VM-0-17-centos ~]# ssh localhost -p 8101






^C

image-20220531113156680

情况三:(直接连接不上,服务器B发出连接不了报错)

1
2
3
4
# 服务器B
[root@VM-0-17-centos ~]# ssh localhost -p 8101
ssh_exchange_identification: read: Connection reset by peer

image-20220531113218786

现在状态

截至时间2022-6-17中午12:52分,服务器A重启后,服务器B也没办法连接上

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
服务器A的crontab日志信息如下
root@raspbian:~# cat /var/log/cron.log
Jun 17 00:05:01 raspbian CRON[15444]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 00:15:01 raspbian CRON[16476]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 00:17:01 raspbian CRON[16674]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 00:20:01 raspbian CRON[16978]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 00:25:01 raspbian CRON[17516]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 00:35:01 raspbian CRON[18539]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 00:40:01 raspbian CRON[19040]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 00:45:01 raspbian CRON[19582]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 00:55:01 raspbian CRON[20582]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 01:00:01 raspbian CRON[21079]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 01:05:01 raspbian CRON[21620]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 01:15:01 raspbian CRON[22651]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 01:17:01 raspbian CRON[22848]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 01:20:01 raspbian CRON[23155]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 01:25:01 raspbian CRON[23693]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 01:35:01 raspbian CRON[24713]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 01:40:01 raspbian CRON[25215]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 01:45:01 raspbian CRON[25754]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 01:55:01 raspbian CRON[26772]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 02:00:01 raspbian CRON[27260]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 02:05:01 raspbian CRON[27812]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 02:15:01 raspbian CRON[28827]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 02:17:01 raspbian CRON[29025]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 02:20:01 raspbian CRON[29336]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 02:25:01 raspbian CRON[29877]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 02:35:01 raspbian CRON[30899]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 02:40:01 raspbian CRON[31405]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 02:45:01 raspbian CRON[31941]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 02:55:01 raspbian CRON[533]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 03:00:01 raspbian CRON[1085]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 03:05:01 raspbian CRON[1675]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 03:15:01 raspbian CRON[2693]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 03:17:01 raspbian CRON[2906]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 03:20:01 raspbian CRON[3229]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 03:25:01 raspbian CRON[3784]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 03:35:01 raspbian CRON[4811]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 03:40:01 raspbian CRON[5313]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 03:45:01 raspbian CRON[5858]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 03:55:01 raspbian CRON[6922]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 04:00:01 raspbian CRON[7425]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 04:05:01 raspbian CRON[7974]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 04:15:01 raspbian CRON[8973]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 04:17:01 raspbian CRON[9173]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 04:20:01 raspbian CRON[9480]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 04:25:01 raspbian CRON[10021]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 04:35:01 raspbian CRON[11045]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 04:40:02 raspbian CRON[11545]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 04:45:01 raspbian CRON[12093]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 04:55:01 raspbian CRON[13117]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 05:00:01 raspbian CRON[13619]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 05:05:01 raspbian CRON[14155]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 05:15:01 raspbian CRON[15165]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 05:17:01 raspbian CRON[15366]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 05:20:01 raspbian CRON[15672]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 05:25:01 raspbian CRON[16215]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 05:35:01 raspbian CRON[17250]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 05:40:01 raspbian CRON[17746]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 05:45:01 raspbian CRON[18285]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 05:55:01 raspbian CRON[19301]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 06:00:01 raspbian CRON[19800]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 06:05:01 raspbian CRON[22560]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 06:15:01 raspbian CRON[23560]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 06:17:01 raspbian CRON[23760]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 06:20:01 raspbian CRON[24067]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 06:25:01 raspbian CRON[24615]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
Jun 17 06:25:01 raspbian CRON[24616]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 06:25:02 raspbian cracklib: no dictionary update necessary.
Jun 17 06:35:01 raspbian CRON[25732]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 06:40:01 raspbian CRON[26237]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 06:45:01 raspbian CRON[26777]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 06:55:01 raspbian CRON[27789]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 07:00:01 raspbian CRON[28292]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 07:05:01 raspbian CRON[28833]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 06:17:02 raspbian cron[412]: (CRON) INFO (pidfile fd = 3)
Jun 17 06:17:02 raspbian cron[412]: (CRON) INFO (Running @reboot jobs)
Jun 17 06:17:03 raspbian CRON[569]: (root) CMD (mount --bind /configuration /www/wwwroot/orange/mount_disk/)
Jun 17 06:17:03 raspbian CRON[570]: (root) CMD (/configuration/script/ssh_reverse_proxy_daemon.sh)
Jun 17 06:17:03 raspbian CRON[572]: (root) CMD (/configuration/script/ssh_reverse_proxy.sh )
Jun 17 07:56:17 raspbian CRON[5396]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
Jun 17 07:56:17 raspbian cracklib: no dictionary update necessary.
Jun 17 08:00:01 raspbian CRON[7985]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 08:05:01 raspbian CRON[8241]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 08:15:01 raspbian CRON[8717]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 08:17:01 raspbian CRON[8839]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 08:20:01 raspbian CRON[8995]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 08:25:01 raspbian CRON[9252]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 08:35:01 raspbian CRON[9750]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 08:40:01 raspbian CRON[10002]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 08:45:01 raspbian CRON[10263]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 08:55:01 raspbian CRON[10760]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 09:00:01 raspbian CRON[11020]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 09:05:01 raspbian CRON[11280]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 09:15:01 raspbian CRON[11749]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 09:17:01 raspbian CRON[11863]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 09:20:01 raspbian CRON[12055]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 09:25:01 raspbian CRON[12401]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 09:35:01 raspbian CRON[12917]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 09:40:01 raspbian CRON[13202]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 09:45:01 raspbian CRON[13470]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 09:47:36 raspbian cron[409]: (CRON) INFO (pidfile fd = 3)
Jun 17 09:47:36 raspbian cron[409]: (CRON) INFO (Running @reboot jobs)
Jun 17 09:47:37 raspbian CRON[571]: (root) CMD (/configuration/script/ssh_reverse_proxy_daemon.sh)
Jun 17 09:47:37 raspbian CRON[574]: (root) CMD (mount --bind /configuration /www/wwwroot/orange/mount_disk/)
Jun 17 09:47:37 raspbian CRON[575]: (root) CMD (/configuration/script/ssh_reverse_proxy.sh )
Jun 17 09:55:01 raspbian CRON[7749]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 10:00:01 raspbian CRON[8058]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 10:05:01 raspbian CRON[8425]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 10:15:01 raspbian CRON[8920]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 10:17:01 raspbian CRON[9018]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 10:20:01 raspbian CRON[9186]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 10:25:01 raspbian CRON[9438]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 10:35:01 raspbian CRON[9927]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 10:40:01 raspbian CRON[10189]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 10:45:01 raspbian CRON[10449]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 10:55:01 raspbian CRON[10928]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 11:00:01 raspbian CRON[11180]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 11:05:01 raspbian CRON[11439]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 11:15:01 raspbian CRON[12987]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 11:17:01 raspbian CRON[13086]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 11:20:01 raspbian CRON[13246]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 11:25:01 raspbian CRON[13507]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 11:35:01 raspbian CRON[13994]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 11:40:01 raspbian CRON[14264]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 11:45:01 raspbian CRON[14596]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 11:55:01 raspbian CRON[15063]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 12:00:01 raspbian CRON[15319]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 12:05:01 raspbian CRON[15572]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 12:15:01 raspbian CRON[16062]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 12:17:01 raspbian CRON[16156]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 17 12:20:01 raspbian CRON[16328]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 12:25:01 raspbian CRON[16584]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 12:35:01 raspbian CRON[17183]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun 17 12:40:01 raspbian CRON[17629]: (smmsp) CMD (test -x /etc/init.d/sendmail && test -x /usr/share/sendmail/sendmail && test -x /usr/lib/sm.bin/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jun 17 12:43:45 raspbian cron[379]: (CRON) INFO (pidfile fd = 3)
Jun 17 12:43:45 raspbian cron[379]: (CRON) INFO (Running @reboot jobs)
Jun 17 12:43:45 raspbian CRON[518]: (root) CMD (/configuration/script/ssh_reverse_proxy.sh )
Jun 17 12:43:45 raspbian CRON[519]: (root) CMD (/configuration/script/ssh_reverse_proxy_daemon.sh)
Jun 17 12:43:45 raspbian CRON[520]: (root) CMD (mount --bind /configuration /www/wwwroot/orange/mount_disk/) #这是我的一个挂载命令,不构成影响。
Jun 17 12:45:03 raspbian CRON[7329]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)

检查服务器B防火墙

image-20220617125728813

A服务器

image-20220617130523176

B服务器

image-20220617130544082

猜想

1.我的朋友说可能是网络问题,毕竟是国外的服务器,连接过去可能出现丢包。

我的解释是ssh反代基于tcp/ip连接,还是比较可靠的,如果是丢包的话它也会继续发送重连,而且服务器B没有被GFW封杀,我也可以ssh到B服务器上面,理论上我应该是可以反代成功的。

2.我曾经换过内核,令服务器B能够开启bbr极限压缩带宽的使用,我不清楚这个是否构成失败原因。

后续

除了上面的玩法,还能代理WEB页面,由于这个是通过ssh的所以很安全访问http

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 首先提供web的那个服务器要允许ssh转发

sudo nano /etc/ssh/sshd_config
AllowTcpForwarding yes
GatewayPorts yes
PermitOpen any


# 重启ssh服务器
sudo systemctl restart sshd


# 本地开cmd
模板:ssh -L 本地cmd电脑随机端口:127.0.0.1:目标web端口 root@目标web的ip -p 目标ssh端口,默认就22

ssh -L 20000:127.0.0.1:80 root@10.10.93.9 -p 22

Snippet-20241125115951

本地电脑直接输入127.0.0.1:20000就可以访问web了

Snippet-20241125120049

还有-N-i参数可以添加使用,作用分别是不进入终端和使用密钥文件登录

[toc]

单片机吹水

1.学习哪种单片机

51、AVR、MSP430、STM8、STM32、DSP、linux、FPGA

2.学习单片机的最佳办法

  • 鹦鹉学舌
  • 照葫芦画瓢
  • 他山之石,可以攻玉
  • 理论和实践相结合,温故而知新

3.学习单片机的准备工作

  • 要有信心、恒心和耐心
  • 完善的配套流程
  • 计算机一台
  • 51开发板一块

芯片学习

51单片机是对所有兼容Intel8031指令系统的单片机的统称,这一系列的单片机的始祖是Intel的8031单片机,后来随着flash ROM技术的发展,8031单片机取得了长足的进展成为了应用最广泛的8bit单片机之一,他的代表型号就是ATMEL公司的AT89系列。

安装单片机开发环境

安装keil

KEIL C51 软件获取

要在电脑上成功安装 KEIL C51,首先必须要有安装包,我们可以通过万能的百度,搜索关键字“KEIL C51 下载”,上面会有很多下载渠道,也可以在KEIL的官网上下载: https://www.keil.com/download/product/,打开界面如下图所示。

image-20220728220612959

不过我们资料内已经给大家提供了下载好的软件,在资料“\5–开发工具\1-KEILC51 软件”内,直接使用即可,省去了查找下载的时间。我们使用KEIL C51 是 9.01 版本, 如果后面出了更高的版本选择性升级即可,不过也没有必要使用最新的,用习惯了一个软件就行。 使用我们提供下载好的软件包,其内部含有如下图所示文件。

image-20220728220739858

C51V901.exe:是 KEIL C51 软件的安装文件。

keygen_new2032.zip:KEIL C51 破解软件,在 KEIL C51 不破解的情况下只能编译 2K 大小文件,如果工程超过 2K,编译即会报错,因此需要破解。有的电脑系统会误认为该文件是病毒文件,所以这里把它压缩存放。

KEIL C51 软件安装

软件包下载完成之后,我们双击 C51V901.exe 这个应用程序,弹出如下所示对话框。

image-20220728223545240

点击 Next 按钮。 弹出如下对话框。

image-20220728223846155

在红框 2 中勾选上,点击 Next 按钮。弹出如下对话框。

image-20220728224107252

**点击红框 4 选择软件安装的路径,我们这里在 磁盘盘内新建一个文件夹,命名为 KEILC51,将其安装到该文件夹内,方便软件的管理。特别要注意: **

**(1)软件安装保存路径不能出现中文或者特殊字符,否则会出现很多奇怪的错误,到时候很难找问题。 **

(2)不要将 KEIL5 软件和 KEIL4 或者 51 的 KEIL 安装在一个文件夹内。然后点击 Next。弹出如下对话框。

image-20220728225157414

在红色框 6 和 7 中我们随便输入一些东西, 我们这里输入数字11,当然也可以输入空格, 但是一定要输入, 否则红色框 8 就一直是灰色状态,输入完成后点击 Next, 弹出如下对话框。

image-20220728225336184

说明 KEIL C51 软件正在安装,只要等一段时间即可,安装完成以后会出现如下界面。

image-20220728225539980

点击 Finish 按钮完成 KEIL C51 软件的安装过程。KEIL C51 安装完成后在电脑桌面上一般会有一个快捷方式,如下所示:

image-20220728225655136

KEIL C51 软件破解

上一节我们已经安装好了 KEIL C51 编程软件,可以使用它来编译51 单片机一些代码量小于 2K 的工程。但是有时候我们开发的项目可能比较大,程序代码超过了 2K,编译后会报错,因此就需要破解 KEIL C51。下面就来介绍下如何破解。

(1)首先打开 KEIL C51 软件,点击 File/License Management,复制红色框 3 中的 CID。 操作步骤如下:

image-20220728231058888

image-20220728235716845

然后我们打开之前下载的 KEIL C51 软件包,里面还有一个keygen 压缩文件,该压缩文件内含有 keygen_new2032.exe 文件,此文件用于破解。因此需要解压,解压后电脑会误认为该文件为病毒文件,会隔离掉,因此我们需要在弹出病毒隔离窗口时点击找回文件即可。

以管理员模式打开此破解软件 keygen_new2032.exe,将刚才从KEIL C51中复制的 CID 码粘贴到下面红色框 4 中,并且在红色框 5 选择C51,然后点击红色框 6,生成破解码,将此破解码即红色框 7 内容复制到KEIL C51 软件内LIC框中,点击 Add LIC 即可破解,如果破解成功则会显示。操作步骤如下:

image-20220729002023233

image-20220729003425413

如 果 破 解 失 败 , 请 确 认 是 否 使 用 管 理 员 模 式打开KEIL C51 软件和keygen_new2032.exe 破解工具。管理员模式打开方式:选择右键:RunAsAdministrator ,中文系统应该是“以管理员权限运行”,然后就可以正常加licence 了。建议所有用户,都以管理员身份运行,以避免重复破解。至此,我们就将 KEIL C51 软件安装和破解成功。后面就可以使用该软件来编写我们的 51 单片机程序。

实验课程_创建模板

创建文件夹

创建一个名为单片机工程模板的文件夹

image-20230828204727638

创建项目

打开keil,创建项目

image-20230828205007098

然后,选择创建的文件夹,写好文件名

image-20230828205235145

选择Vendor

选择Atmel里面的AT89C52基础数据

image-20230828205501446

image-20230828205701135

然后,掉下面选项

image-20230828205848976

创建main.c代码文本文件

image-20230828210954625

点完后,按ctrl + s,设置文本文件名字为main.c即可

image-20230828211035648

image-20230828211155706

添加main.c到工程文件

image-20230828211557693

image-20230828211659633

image-20230828211714598

其他添加main.c方法

image-20230828212344216

实验课程_设置魔术棒

image-20230828212924815

image-20230828213144515

image-20230828213419473

编译工具栏

image-20230828220302930

  • 第一个是编译当前文件,而且不生成hex
  • 第二个是编译改动的文件,生成hex
  • 第三个是全部文件编译,生产hex

更改字体大小

image-20230828220657738

image-20230828220753881

reg52.h头文件

1
2
#include <reg52.h>   # 直接查C:\Keil\C51\INC里有没有REG52.H
#include "reg52.h" # 先查工程文件夹有没有REG52.H,没有再查C:\Keil\C51\INC

如果在C:\Keil\C51\INC里面没有REG52.H就会报错

image-20230828221740821

实验课程_使用PZ-ISP烧录器

如果我们使用的是STC89C516RD+的处理器,选择带RC的芯片类型,也就是说带RD的就选择带RC的芯片类型,如果不带RD的处理器选择不带RC的芯片类型

image-20230419163408643

实验课程_点亮LED灯

点亮一个LED_D1

LED灯的端口有四组,分别是P0,P1,P2,P3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**************************************************************************************
实验名称:点亮第一个LED
接线说明:
实验现象:下载程序后“LED模块”的D1指示灯点亮
注意事项:
***************************************************************************************/
#include "reg52.h"

sbit LED1=P2^0; //将P2.0管脚定义为LED1

/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{
LED1=0; //LED1端口设置为低电平
while(1)
{

}

}

点亮一个LED_D1_闪烁

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <reg52.h>

typedef unsigned int u16; //使用typedef来为用户自定义的数据类型取一个新的名字
sbit LED1 = P2^1;

void delay_10us(u16 ten_us) //当传2入ten_us=1时,大约延时10us
{
while(ten_us--);
}
void main()
{

while(1)
{
LED1 = 0; //点亮
delay_10us(50000);//大约450ms
LED1 = 1; //熄灭
delay_10us(50000);
}
}

点亮一个LED_D1_流水灯

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**************************************************************************************
实验名称:LED流水灯实验
接线说明:
实验现象:下载程序后“LED模块”的D1-D8指示左右点亮
注意事项:
***************************************************************************************/
#include "reg52.h"
#include "intrins.h"

typedef unsigned int u16; //对系统默认数据类型进行重定义
typedef unsigned char u8;

#define LED_PORT P2 //使用宏定义P2端口

/*******************************************************************************
* 函 数 名 : delay_10us
* 函数功能 : 延时函数,ten_us=1时,大约延时10us
* 输 入 : ten_us
* 输 出 : 无
*******************************************************************************/
void delay_10us(u16 ten_us)
{
while(ten_us--);
}

/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{
u8 i=0;

LED_PORT=~0x01;
delay_10us(50000);
while(1)
{
//方法1:使用移位+循环实现流水灯
// for(i=0;i<8;i++)
// {
// LED_PORT=~(0x01<<i); //将1右移i位,然后取反将结果赋值到LED_PORT
// delay_10us(50000);
// }

//方法2:使用循环+_crol_或_cror_函数实现流水灯
for(i=0;i<7;i++) //将led左移一位
{
LED_PORT=_crol_(LED_PORT,1);
delay_10us(50000);
}
for(i=0;i<7;i++) //将led右移一位
{
LED_PORT=_cror_(LED_PORT,1);
delay_10us(50000);
}
}
}

点亮一个LED_D1库函数实现_流水灯

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**************************************************************************************
实验名称:LED流水灯实验
接线说明:
实验现象:下载程序后“LED模块”的D1-D8指示左右点亮
注意事项:
***************************************************************************************/
#include "reg52.h"
#include "intrins.h"

typedef unsigned int u16; //对系统默认数据类型进行重定义
typedef unsigned char u8;

#define LED_PORT P2 //使用宏定义P2端口

/*******************************************************************************
* 函 数 名 : delay_10us
* 函数功能 : 延时函数,ten_us=1时,大约延时10us
* 输 入 : ten_us
* 输 出 : 无
*******************************************************************************/
void delay_10us(u16 ten_us)
{
while(ten_us--);
}

/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{
u8 i=0;

LED_PORT=~0x01;
delay_10us(50000);
while(1)
{
//方法1:使用移位+循环实现流水灯
// for(i=0;i<8;i++)
// {
// LED_PORT=~(0x01<<i); //将1右移i位,然后取反将结果赋值到LED_PORT
// delay_10us(50000);
// }

//方法2:使用循环+_crol_或_cror_函数实现流水灯
for(i=0;i<7;i++) //将led左移一位
{
LED_PORT=_crol_(LED_PORT,1);
delay_10us(50000);
}
for(i=0;i<7;i++) //将led右移一位
{
LED_PORT=_cror_(LED_PORT,1);
delay_10us(50000);
}
}
}

实验课程_蜂鸣器之无源蜂鸣器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**************************************************************************************
实验名称:蜂鸣器实验
接线说明:
实验现象:下载程序后蜂鸣器发出声音,一段时间后关闭
注意事项:
***************************************************************************************/
#include "reg52.h"

typedef unsigned int u16; //对系统默认数据类型进行重定义
typedef unsigned char u8;

sbit BEEP=P2^5; //将P2.5管脚定义为BEEP

/*******************************************************************************
* 函 数 名 : delay_10us
* 函数功能 : 延时函数,ten_us=1时,大约延时10us
* 输 入 : ten_us
* 输 出 : 无
*******************************************************************************/
void delay_10us(u16 ten_us)
{
while(ten_us--);
}

/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{
u16 i=2000;

while(1)
{
while(i--)//循环2000次
{
BEEP=!BEEP;//产生一定频率的脉冲信号
delay_10us(100);
}
i=0;//清零
BEEP=0;//关闭蜂鸣器
}
}

实验课程_静态数码管

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**************************************************************************************
实验名称:静态数码管实验
接线说明:
实验现象:下载程序后“静态数码管模块”显示数字0
注意事项:
***************************************************************************************/
#include "reg52.h"

typedef unsigned int u16; //对系统默认数据类型进行重定义
typedef unsigned char u8;

#define SMG_A_DP_PORT P0 //使用宏定义数码管段码口

//共阴极数码管显示0~F的段码数据
u8 gsmg_code[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{
SMG_A_DP_PORT=~gsmg_code[0];//将数组第1个数据赋值给数码管段选口
while(1)
{

}
}