Skip to content
Eternal Center

Eternal Center

  • Single-Node (单节点)
    • System (系统)
    • Service (服务)
    • Database (数据库)
    • Container (容器)
    • Virtualization (虚拟化)
  • Multi-Node (多节点)
    • Cluster (集群)
    • Big Data (大数据)
    • Cloud Computing (云计算)
    • Batch Processing (批量处理)
  • Approach (方式方法)
    • Languages (语言)
    • Ideas (思路)
    • Programing (编程)
    • Project (项目)
  • Eternity (永恒)
    • News (消息)
    • Creations (创作)
    • Classics (经典)
    • Legends (传说)
    • Chronicle (编年史)
    • FNIOS (宇宙公民开源学院)

Category: System Login Security (系统登录安全)

Posted on April 28, 2022April 28, 2025

[步骤] Linux 系统被删根 (/)目录 (rm -rf /*) 后锁定删根 (/) 目录 (rm -rf /*) 用户的尝试 (系统层面)

正文:

步骤一:系统被删根 (rm -rf /*) 后的现象总结

1) 系统无法被 ssh
2) 通过 console 口登录系统在输入密码时会卡住
3) 尝试将当前根 “/” 目录从救援模式的根 “/” 目录切换到系统的根 “/” 目录时会报错 “chroot: failed to run command #/bin/bash#: No such file or directory”
4) 重启系统后无法进入系统,并提示:/grub2/i386-pc/normoal.mod not found gpt
5)在救援模式显示 /boot 目录里的文件时,可能会发现此目录下只有 grub2 目录,而此 grub2 目录里也是空的
6) 在救援模式显示 /bin 目录时,会显示并无此目录
7) 在救援模式显示 /etc 目录里的文件时,可能会发现此目录下只有 lvm 文件

步骤二:挂载官方镜像

(步骤略)

步骤三:登录拯救模式

3.1 选择通过光盘启动

(步骤略)

3.2 进入拯救模式

(步骤略)

3.3 登录拯救模式

rescue login:root

步骤四:在救援模式确定系统的根 “/” 目录分区

(步骤略)

(
补充:
1) 物理分区可以使用 lsblk 命令、fdisk -l 或 cat /proc/partitions 命令辅助确定
2) 逻辑分区还可以可以使用 pvs 命令、lvs 命令或 lvdisplay 命令辅助确定
)

步骤五:在救援模式将系统的分区挂载到救援模式的 /mnt 目录

5.1 在救援模式将系统的根分 “/” 区挂载到救援模式的 /mnt 目录

5.1.1 在救援模式将系统的根 “/” 分区挂载到救援模式的 /mnt 目录
tty1:rescue:~ # mount <root spartition> /mnt

(
补充:
1) 如果是物理分区,系统的根 “/” 分区就在救援模式的 /dev/ 目录里,例如救援模式的 /dev/sda1
2) 如果是逻辑分区,Rocky Linux & RHEL 的系统根 “/” 分区就是救援模式里的 /dev/<volume group>/<logical volume> 例如救援模式里的 /dev/vg/lv,openSUSE & SUSE 的系统根 “/” 分区就是救援模式里的 /dev/mapper/<volume group>-<logical volume> 例如救援模式里的 /dev/mapper/vg-lv
)

5.1.2 在救援模式确认系统的根 “/” 分区已经挂载到救援模式的 /mnt 目录
tty1:rescue:~ # ls /mnt

(补充:此时可以看到 /mnt 目录下有系统根 “/” 目录下的各个目录,例如 /etc /root 等)

5.2 在救援模式将救援模式的 /dev 目录关联到救援模式的 /mnt/dev 目录

tty1:rescue:~ # mount --rbind /dev /mnt/dev

(
补充:
1) 此时所有对救援模式的 /mnt/dev 目录的访问都会变成对救援模式的 /dev 目录的访问
2) 步骤 5.2、步骤 5.3 和步骤 5.4 也可以用以下命令代替:

tty1:rescue:~ # for i in proc sys dev; do mount --rbind /$i /mnt/$i ; done

)

5.3 在救援模式将救援模式的 /proc 目录关联到救援模式的 /mnt/proc 目录

tty1:rescue:~ # mount --rbind /proc /mnt/proc

(
补充:
1) 此时所有对救援模式的 /mnt/proc 目录的访问都会变成对救援模式的 /proc 目录的访问
2) 步骤 5.2、步骤 5.3 和步骤 5.4 也可以用以下命令代替:

tty1:rescue:~ # for i in proc sys dev; do mount --rbind /$i /mnt/$i ; done

)

5.4 在救援模式将救援模式的 /sys 目录关联到救援模式的 /mnt/sys 目录

tty1:rescue:~ # mount --rbind /sys /mnt/sys

(
补充:
1) 此时所有对救援模式的 /mnt/sys 目录的访问都会变成对救援模式的 /sys 目录的访问
2) 步骤 5.2、步骤 5.3 和步骤 5.4 也可以用以下命令代替:

tty1:rescue:~ # for i in proc sys dev; do mount --rbind /$i /mnt/$i ; done

)

5.5 在救援模式将救援模式的 /run 目录关联到救援模式的 /mnt/run 目录 (选做)

tty1:rescue:~ # mount --rbind /run /mnt/run

(补充:此时所有对救援模式的 /mnt/run 目录的访问都会变成对救援模式的 /run 目录的访问)

步骤六:显示系统被删根 “/” 目录 (rm -rf /*) 后的现象

6.1 尝试将当前根 “/” 目录从救援模式的根 “/” 目录切换到系统的根 “/” 目录时会报错 “chroot: failed to run command #/bin/bash#: No such file or directory”

tty1:rescue:~ # chroot /mnt
chroot: failed to run command #/bin/bash#: No such file or directory

(补充:这里以 /mnt 作为系统根 “/” 目录为例)

(注意:因为在使用 rm -rf /* 命令删过根 “/” 以后,/bin/bash 已经被删除,所以会报错:chroot: failed to run command #/bin/bash#: No such file or directory)

6.2 在救援模式显示 /boot 目录里的文件时,会发现此目录下只有 grub2 目录,而此 grub2 目录里也是空的

tty1:rescue:~ # ls /boot 
grub2
tty1:rescue:~ # ls /boot

此步骤也可以通过以下方法实现:

tty1:rescue:~ # ls -l /mounts/mp_0001/boot
total 0
......grub2
tty1:rescue:~ # ls -l /mounts/mp_0001/boot/grub2
total 0

6.3 在救援模式显示 /bin 目录时,会显示并无此目录

tty1:rescue:~ # ls /mnt/bin
ls: cannot access '/mnt/bin' : No such file or directory

6.4 在救援模式显示 /etc 目录里的文件时,会发现此目录下只有 lvm 文件

tty1:rescue:~ # ls /etc/
lvm

步骤七:在救援模式修复系统的 /bin 目录和里面的文件

7.1 在救援模式创建 /mnt/bin 目录

tty1:rescue:~ # mkdir /mnt/bin

7.2 在救援模式挂载官方镜像

7.2.1 在救援模式创建用于挂载镜像的 /media 目录
tty1:rescue:~ # mkdir /media
7.2.2 在救援模式挂将官方镜像挂载到 /media 目录
tty1:rescue:~ # mount /dev/dvd /media

7.3 在救援模式安装 bash 软件

7.3.1 在救援模式拷贝 bash 的 RPM 文件 (软件包) 到当前目录
tty1:rescue:~ # cp /media/suse/x86_64/bash-4.3-83.23.1.x86_64.rpm .

(补充:这里以拷贝 /media/suse/x86_64/bash-4.3-83.23.1.x86_64.rpm)

7.3.2 在救援模式创建用于提取 bash 的 RPM 文件 (软件包) 的 bash 目录
tty1:rescue:~ # mkdir bash
7.3.3 在救援模式进入 bash 目录
tty1:rescue:~ # cd bash
7.3.4 在救援模式提取 bash 的 RPM 文件 (软件包) 里的子文件
tty1:rescue:~ /bash # rpm2cpio ../bash-4.3-83.23.1.x86_64.rpm | cpio -ivd

(补充:这里以提取 bash-4.3-83.23.1.x86_64.rpm RPM 文件 (软件包) 为例)

7.3.5 在救援模式显示提取 bash 的 RPM 文件 (软件包) 里的子文件后生成的目录
tty1:rescue:~ /bash # ls
bin etc usr

7.4 在救援模式将提取的 bash 的 RPM 文件 (软件包) 里的子文件拷贝到 /mnt/bin 目录

tty1:rescue:~ /bash # cp -rpv bin/* /mnt/bin
'bin/bash' -> '/mnt/bin/bash'
'bin/sh' -> '/mnt/bin/sh'

7.5 在救援模式拷贝 /bin/bash 文件依赖的动态链接库到 /mnt 目录下存放 /bin/bash 文件依赖的动态链接库的目录

7.5.1 在救援模式查看 /bin/bash 文件依赖的动态链接库
tty1:rescue:~ /bash # ldd /bin/bash
7.5.2 在救援模式在 /mnt 目录下创建存放 /bin/bash 文件依赖的动态链接库的目录
7.5.2.1 创建 lib 目录
tty1:rescue:~ /bash # mkdir /mnt/lib
7.5.2.2 创建 lib64 目录
tty1:rescue:~ /bash # mkdir /mnt/lib64
7.5.3 在救援模式拷贝 /bin/bash 文件依赖的动态链接库到 /mnt 目录下存放 /bin/bash 文件依赖的动态链接库的目录
7.5.3.1 拷贝存放在 lib 目录的动态链接库
tty1:rescue:~ /bash # cp /lib/x86_64-linux-gnu/liblsp.so /mnt/lib
tty1:rescue:~ /bash # cp /lib/x86_64-linux-gnu/libtinfo.so.5 /mnt/lib
tty1:rescue:~ /bash # cp /lib/x86_64-linux-gnu/libd1.so.2 /mnt/lib
tty1:rescue:~ /bash # cp /lib/x86_64-linux-gnu/libc.so.6 /mnt/lib
7.5.3.2 拷贝存放在 lib64 目录的动态链接库
tty1:rescue:~ /bash # cp /lib64/ld-linux-x86-64.so.2 /mnt/lib64

步骤八:将当前的根 “/” 目录从救援模式的根 “/” 目录切换到系统的根 “/” 目录

8.1 将当前的根 “/” 目录从救援模式的根 “/” 目录切换到系统的根 “/” 目录

tty1:rescue:~ /bash # chroot /mnt

(补充:这里以 /mnt 作为系统根 “/” 目录为例)

8.2 在系统模式下挂载所有需要开机自动挂载的目录

bash-4.3# mount -a

8.3 在系统模式下确认当前根 “/” 目录下的目录

bash-4.3# ls
bin boot dev home lib lib64 mnt opt proc root run sbin selinux srv sys tmp usr var

步骤九:锁定有删根 “/” 目录 (rm -rf /*) 操作的用户

9.1 在系统模式显示历史命令以确认有没有用户输入过 rm -rf /* 命令

bash-4.3# history | less

9.2 在系统模式显示用户登录记录

bash-4.3# last | less

(补充:此时会显示最后登录系统的用户、登录时间、且可能最后 1 个登录系统的用户无退出时间)

9.3 根据步骤 9.1 和步骤 9.2 推测是哪个用户进行过删根 “/” 目录 (rm -rf /*) 操作

(步骤略)

参考文献:

https://www.suse.com/support/kb/doc/?id=000018770

Posted on April 25, 2022November 24, 2022

[内容] iptables 防火墙规则持久化 (让防火墙规则开机自启)

内容一:Rocky Linux & RHEL iptables 防火墙规则持久化

# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

内容二:Rocky Linux & RHEL 和 openSUSE & SUSE iptables 防火墙规则持久化

2.1 导出现在 iptables 防火墙的规则

# iptables-save > /root/iptables_save

(补充:这里以将 iptables 防火墙规则导出到 /root/iptables_save 文件为例)

2.2 创建用于加载 iptables 防火墙规则的 systemctl 管理文件

# vim /etc/systemd/system/iptables_save.service

创建以下内容:

[Unit]
Description=iptables_save
After=default.target

[Service]
Type=oneshot
ExecStart=/usr/sbin/iptables-restore < /root/iptables_save

[Install]
WantedBy=default.target

(补充:这里以创建 systemctl 管理文件 /etc/systemd/system/iptables_save.service 将 /root/iptables_save 文件里的内容导入到 iptables 防火墙为例)

2.3 加载刚刚创建的 systemctl 管理文件

# systemctl daemon-reload

2.4 给刚刚创建的 systemctl 管理文件添加执行权限

# chmod u+x /etc/systemd/system/iptables_save.service

(补充:这里以给 systemctl 管理文件 /etc/systemd/system/iptables_save.service 添加执行权限为例)

2.5 让防火墙规则开机自启

# systemctl enable iptables_save.service

(补充:这里以开机自启 iptables_save.service 服务为例)

Posted on April 25, 2022October 19, 2022

[内容] iptables 防火墙规则的导出和导入

内容一:导出 iptables 防火墙规则

# iptables-save > /root/iptables_save

(补充:这里以将 iptables 防火墙规则导出到 /root/iptables_save 文件为例)

内容二:导入 iptables 防火墙规则

# iptables-restore < /root/iptables_save

(补充:这里以将 /root/iptables_save 文件里的内容导入到 iptables 防火墙为例)

Posted on April 11, 2022November 22, 2024

[排错] 解决 Linux 运行 authselect 命令时报错 “[error] [/etc/authselect/system-auth] has unexpected content!” 或者 “[error] [/etc/authselect/password-auth] has unexpected content!”

报错代码

[error] [/etc/authselect/system-auth] has unexpected content!
[error] [/etc/authselect/password-auth] has unexpected content!
[error] Unexpected changes to the configuration were detected.
[error] Refusing to activate profile unless those changes are removed or overwrite is requested.

或者:

[error] [/etc/authselect/system-auth] has unexpected content!
[error] Unexpected changes to the configuration were detected.
[error] Refusing to activate profile unless those changes are removed or overwrite is requested.

或者:

[error] [/etc/authselect/password-auth] has unexpected content!
[error] Unexpected changes to the configuration were detected.
[error] Refusing to activate profile unless those changes are removed or overwrite is requested.

分析

/etc/authselect/system-auth 文件或 /etc/authselect/password-auth 文件是不应该被手动修改的,如果被手动修改了,再使用 authselect select sssd 命令或者 authselect apply-changes 命令时则会有此类报错

解决方法

# authselect apply-changes

(注意:此方法会刷新 /etc/authselect/system-auth 文件和 /etc/authselect/password-auth 文件里的所有内容)

Posted on February 12, 2022June 19, 2022

[内容] Linux 用户登录相关日志

内容一:所有用户正在登录的记录

1.1 所有用户正在登录的记录

/var/run/utmp

1.1 所有用户正在登录记录的显示

# who

或者:

# w

或者:

# users

内容二:所有用户登录和登出的记录

2.1 所有用户登录和登出的记录

/var/log/wtmp

2.1 所有用户登录和登出记录的显示

# last
Linux 命令 last
wtmp 日志保存时间默认策略的设置

(注意:last 命令显示用户时最多只会显示前 8 个字符)

或者:

# ac

内容三:所有用户最后一次登录的记录

3.1 所有用户最后一次登录的记录

/var/log/lastlog

3.2 所有用户最后一次登录记录的显示

# lastlog

内容四:所有错误登录尝试的记录

4.1 所有错误登录尝试的记录

/var/log/btmp

4.2 所有错误登录尝试记录的显示

# lastb

内容五:所有信息 (其中也包括用户登录相关的记录)

/var/log/messages

内容六:所有用户登录相关的记录

/var/log/secure

Posts pagination

Previous page Page 1 … Page 13 Page 14 Page 15 … Page 24 Next page

Aspiration (愿景):

Everyone can achieve self-achievement and self-happiness fairly

每个人都能公平地实现自我成就和自我幸福

Logo (徽标):

Additional Information (其他信息):

About     Manual     Clone     Contact
Disclaimer     Friendly Links     Donation

关于     手册     克隆     联系
免责声明     友情链接     捐赠

Search Inside Website (站内搜索)

Search Outside Website (站外搜索):

Google         Wikipedia         Bing

Eternal URL (永恒网址):

https://eternity.eternalcenter.com Will be last access method / 将是最后的访问方式

Proudly powered by LNMP Proudly powered by WordPress