https://baijiahao.baidu.com/s?id=1726897688052574035&wfr=spider&for=pc
CentOS Rescue 模式启用ssh远程连接
插入系统iso镜像光盘,重启 选择 TroubleshootingRescue a CentOS Linux system
1、启用救援模式的sshd服务
方式一 修改启动菜单
Rescue a CentOS Linux system 按Tab键
在vmlinuz initrd=...后添加 inst.sshd=1 回车启动
方式二 救援模式中启动sshd
sh-4.2# chroot /mny/sysimage/bash-4.2# /usr/sbin/sshd
2、配置救援模式的IP地址
这里主要使用ip命令配置IP地址及网关
2.1 激活网卡
如果网卡处于未激活状态,则使用下面命令激活
ip link set dev <网卡名称> up这里应为ip link set dev ens33 up
2.2 设置网卡IP
设置网卡命令为
ip addr add <ip address>/<netmask> dev <device>这里应为ip addr add 10.10.10.15/24 dev ens33
2.3 设置网卡网关
设置网关命令为ip route add default via <gateway ip address>这里应为ip route add default via 10.10.10.2
2.4 检查网络配置
查看ip地址ip addr查看网关ip route show或者route -n
3、ssh连接测试
[root@envir-01 usr]# ssh 10.10.10.15The authenticity of host '10.10.10.15 (10.10.10.15)' can't be established.ECDSA key fingerprint is SHA256:AHZ4alIXwDR6eEB+WohfuaRAoKnE5wjqsA7Ljl2twb8.ECDSA key fingerprint is MD5:8a:85:1d:22:bf:06:4c:ee:da:40:95:de:51:7b:46:0b.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '10.10.10.15' (ECDSA) to the list of known hosts.[anaconda root@localhost ~]# lslorax-packages.log[anaconda root@localhost ~]#
注意
两种启用ssh方法的差异
方式一:ssh连接不需要输入用户和密码
方式二: ssh连接需要输入用户和密码
不管哪种方式,都需要手动配置IP地址
1、进入救援模式并启用网络
2、启用sshd服务
bash-4.1# chroot /mnt/sysimage/sh-4.1# /sbin/service sshd start
网上有教程还使用了mount /dev/pts 命令,经测试此命令不需要
3、测试连接
注意,连接ssh,需要输入用户和密码
[root@envir-01 usr]# ssh 10.10.10.14The authenticity of host '10.10.10.14 (10.10.10.14)' can't be established.RSA key fingerprint is SHA256:yCcAbM2hu6CJCiDphpFmPIpgS/z3NL0W45sQb8z0Ga8.RSA key fingerprint is MD5:e7:f9:9f:48:1b:f8:85:7c:00:90:5c:40:76:b4:2d:90.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '10.10.10.14' (RSA) to the list of known hosts.root@10.10.10.14's password: Last login: Tue Sep 10 18:51:03 2019 from 10.10.10.10[root@localhost ~]# ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:d2:18:cf brd ff:ff:ff:ff:ff:ffinet 10.10.10.14/24 brd 10.10.10.255 scope global eth0inet6 fe80::20c:29ff:fed2:18cf/64 scope link valid_lft forever preferred_lft forever