运维开发网

克隆虚拟机和相互登录

运维开发网 https://www.qedev.com 2021-02-15 12:39 出处:51CTO 作者:纸皮灯笼
克隆虚拟机和相互登录做实验时,需要多台机器,此时用克隆虚拟机就会提高效率,节省部署时间。1.关闭当前需要克隆的虚拟机。点击虚拟机---管理---克隆,按照提示直到创建完成。2.创建完成后,启动新的虚拟机。修改IP地址,删除UUID,以防对原虚拟机造成影响。3.重启网络服务,查看是否有正确IP,检测IP连通性。4.修改主机名,修改完后,exit退出重新进入。5.开启原虚拟机,修改主机名。6.相互连接

克隆虚拟机和相互登录

做实验时,需要多台机器,此时用克隆虚拟机就会提高效率,节省部署时间。

1.关闭当前需要克隆的虚拟机。点击虚拟机---管理---克隆,按照提示直到创建完成。

克隆虚拟机和相互登录

克隆虚拟机和相互登录

克隆虚拟机和相互登录

克隆虚拟机和相互登录

克隆虚拟机和相互登录

克隆虚拟机和相互登录

2.创建完成后,启动新的虚拟机。修改IP地址,删除UUID,以防对原虚拟机造成影响。

克隆虚拟机和相互登录

3.重启网络服务,查看是否有正确IP,检测IP连通性。

克隆虚拟机和相互登录

4.修改主机名,修改完后,exit退出重新进入。

克隆虚拟机和相互登录

克隆虚拟机和相互登录

5.开启原虚拟机,修改主机名。

克隆虚拟机和相互登录

克隆虚拟机和相互登录

克隆虚拟机和相互登录

6.相互连接

w查看两台机器的连接数,从哪里连接的。

克隆虚拟机和相互登录

克隆虚拟机和相互登录

用2号机器ssh1号机器。

[[email protected] ~]# ssh 192.168.237.128
The authenticity of host '192.168.237.128 (192.168.237.128)' can't be established.
ECDSA key fingerprint is SHA256:85mFXFmTEONGhiXkOy1wXiSc/ArENhDNw+IEqmnJ5vY.
ECDSA key fingerprint is MD5:a4:d9:13:b1:30:42:f4:5a:3d:9a:3c:e2:aa:85:ae:e8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.237.128' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Last login: Sat Feb 13 22:34:13 2021 from 192.168.237.1

此时再用w查看连接情况

[[email protected] ~]# w
 22:52:41 up 18 min,  2 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             [email protected]   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.237.1    22:34    9:13   0.01s  0.01s -bash
root     pts/1    192.168.237.127  22:49    1.00s  0.02s  0.01s w
[[email protected] ~]# w
 22:43:31 up 9 min,  1 user,  load average: 0.00, 0.03, 0.05
USER     TTY      FROM             [email protected]   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.237.1    22:34    3.00s  0.01s  0.00s w
[[email protected] ~]# w
 22:52:52 up 19 min,  2 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             [email protected]   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.237.1    22:34    4.00s  0.01s  0.00s w
root     pts/1    192.168.237.127  22:49   12.00s  0.01s  0.01s -bash

两台机器已经互联。

ssh也可用另外两种方式连接。

1.用户名 ssh [email protected]

2.指定端口 ssh -p 端口 ip

[[email protected] ~]# ssh [email protected]
[email protected]'s password: 
Last login: Sat Feb 13 22:49:02 2021 from 192.168.237.127
[[email protected] ~]# exit
登出
Connection to 192.168.237.128 closed.
[[email protected] ~]# ssh -p 22 192.168.237.128
[email protected]'s password: 
Last login: Sat Feb 13 22:59:40 2021 from 192.168.237.127

7.密钥认证连接

在2号机设置私钥,1号机公钥

输入ssh-keygen后提示密钥对的存放路径,这里我选择默认回车。之后提示输入密码,默认为空,回车。

[[email protected] ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:MOLQdi6VT8VQ3e4+v4QJ2Jjh/cGzE7sFBf+229EK9c8 [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|        .+o. o   |
|   .   . .. . +  |
|  . + * ..   . o |
|   + = =. B . o .|
|    o . S= + B. o|
|     .      [email protected]|
|            .O =o|
|             .Bo=|
|             ..=E|
+----[SHA256]-----+

复制公钥到1号机,注释是哪里来的公钥。

[[email protected] ~]# ls /root/.ssh/
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[[email protected] ~]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJRiZvX1F/yeqry6Jnp16pMPI0C1Tc+5WGTsEdcX6M66EPDeLZMq0/4rSTQBK5R5C2VXNPQJD5Jw6XM+lTTHRF1pHHAhSZiZ/GYKYRS8jNwN3mBJa60uI8VZv6UJNFeeelm44djb1q+iCepcYDO0WW0ug2bYJC5BnA9X5uYe0ENAhNBnZqSWgUAcduXkEBoedAgMRp86ttKB7UyGJ3Xlr9/dAoSWX4ZZLvBwDu+VGNQcunR50L+o85bNKc54ZTuhQnDOhdjIKZDe88WZTQshdNPWli2gFIgFVf1JkB7OvqjTOtgWLy9I+ab/UTnmXlTrd8qjd2lVk9C5uxv0IiYyLB [email protected]
[[email protected] ~]# vi /root/.ssh/authorized_keys

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt1vgyaIFQhOxm6AS70JW7HCd+eU9CjNJT3uW6U6+/qksyZvLwQcOY90VzO8thvSlIWaQFA62VlV7Ovq2ZV7zhdjm/JFeAJhWrbsF0td9KBQmf++Q/niePVnkkibRzzqRrHlJe0t9LYmCn7kr7aGKUA26hUIvhR0/30l7Bmcv8cgMEYaapWgAjCMszARIO2AIOkBPDGLpN4clhHNbbteFLBEpGDPHVzw3PUgymhQuGni1jkprYpO4oYDL5huk1t30TZVX7mEdB5Z5KvO543/8wU9xmT2D104QhvorYKTGTGUCMlP7LAkPeuFjNE5EwjoGXNgnWVKQ6RF8HgAaGFPvDw==
##centos 7-Xshell

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJRiZvX1F/yeqry6Jnp16pMPI0C1Tc+5WGTsEdcX6M66EPDeLZMq0/4rSTQBK5R5C2VXNPQJD5Jw6XM+lTTHRF1pHHAhSZiZ/GYKYRS8jNwN3mBJa60uI8VZv6UJNFeeelm44djb1q+iCepcYDO0WW0ug2bYJC5BnA9X5uYe0ENAhNBnZqSWgUAcduXkEBoedAgMRp86ttKB7UyGJ3Xlr9/dAoSWX4ZZLvBwDu+VGNQcunR50L+o85bNKc54ZTuhQnDOhdjIKZDe88WZTQshdNPWli2gFIgFVf1JkB7OvqjTOtgWLy9I+ab/UTnmXlTrd8qjd2lVk9C5uxv0IiYyLB [email protected]
##centos02

检查2号机能否连上1号机

[[email protected] ~]# ssh -p 22 192.168.237.128
Last login: Sat Feb 13 23:01:22 2021 from 192.168.237.127
[[email protected] ~]# 

此时连接成功,且不需要密码。

如果连接不成功,检查1号机seLinux是否有关闭。

[[email protected] ~]# getenforce 
Enforcing
[[email protected] ~]# setenforce 0
[[email protected] ~]# getenforce 
Permissive
[[email protected] ~]# 

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号