Linux 远程连接虚拟机

一、主机名和列表

1.默认的主机名是localhost.localhostDomain
2.修改主机名的两种方式:
(1)hostnamectl set-hostname 新主机名
(2)vi /etc/hostname 在其中把【主机名】改成【新主机名】(需要重启 才能生效)
3.主机列表 vi /etc/hosts 在其中加上:主机Ip地址:主机名
4. ssh 用户名@主机名/ip地主:连接到对应的主机
5、添加互信(每台机器都要对其他机器做下面的动作)
(1)生成秘钥:ssh-******
(2)赋值到秘钥校验文件:cat .ssh/id_rsa.pub > .ssh/authorized_keys
(3)传输到需要互信的机器:ssh-copy-id -i .ssh/id_rsa.pub -p22 用户名 @ 主机名

二、详细步骤

一、远程连接
ssh协议:Linux远程连接是基于SSH协议的
查看主机地址:ifconfig

1.克隆虚拟机
(切记勿忘更改适配器1.2的MAC地址,不可与克隆虚拟机的相同)
更改IP地址
保存后启动:systemctl restart network
Linux 远程连接虚拟机

2.打开虚拟机
主机100 克隆机101
ssh @root192.168.克隆地址 ssh 主机地址
exit == exit
vi /etc/hostname (展示系统名称)==
改名可以为:centos03 centos031
hostnamectl (查看最新系统机名) ==
hostnamectl set-hostname centos03 hostnamectl set-hostname centos031
ssh [email protected](自己连接自己) ssh [email protected]
exit(出现logout) ==
vi /etc/hosts ==
添加:192.168.195.100 centos03 ==
192.168.195.101 centos031 ==
保存退出即可
ssh [email protected] ssh [email protected]
hostname(查看是否连接成功) ==
成功后 exit ==
有个弊端,每次都要输密码,可以继续优化,可以添加互信*
ssh ****** [-h] ==
cat .ssh/id_rsa.pub > .ssh/authorized_keys ==
ssh-copy-id -i .ssh/id_rsa.pub -p22 [email protected] ==
ssh centos031(测试是否可以直接连接) ==
exit