花店营销策略超市门户网站建设,学校网站建设责任书,有实力高端网站设计地址,wordpress模版哪个好环境准备#xff1a; 将虚拟机1恢复快照#xff0c;然后手动配置一个NAT模式IP为192.168.200.100#xff0c;hostname设置为fuwu1 将虚拟机1复制为虚拟机2#xff0c;然后手动配置一个NAT模式IP为192.168.200.200#xff0c;hostname设置为fuwu2 windows准备 xshell 或 pu…
环境准备 将虚拟机1恢复快照然后手动配置一个NAT模式IP为192.168.200.100hostname设置为fuwu1 将虚拟机1复制为虚拟机2然后手动配置一个NAT模式IP为192.168.200.200hostname设置为fuwu2 windows准备 xshell 或 putty 或 MobaXterm 或 SecureCRT建议xshell
一、ssh命令登录以及Xshell登录
1、在虚拟机2上ssh登录虚拟机1
[rootfuwu2 ~]# ssh root192.168.200.100
The authenticity of host 192.168.200.100 (192.168.200.100) cant be established.
ECDSA key fingerprint is SHA256:LKt/z3vCmOSqtKERl7omW7L4kC0ngZTi7kimfHf5g.
ECDSA key fingerprint is MD5:2f:be:5b:f6:4b:d7:dc:44:ef:0e:c1:c4:ab:cd:a1:a4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 192.168.200.100 (ECDSA) to the list of known hosts.
root192.168.200.100s password:
Last login: Wed Aug 17 20:27:22 2022
[rootfuwu1 ~]#
2、虚拟机1上退出登录
[rootfuwu1 ~]# exit
登出
Connection to 192.168.200.100 closed.
3、Xshell登录虚拟机1
----界面演示---- 二、验证配置禁止root用户远程登录后效果
1、虚拟机1上修改ssh配置文件禁用root远程登录
[rootfuwu1 ~]# vi /etc/ssh/sshd_config 找到 #PermitRootLogin yes 一行将 # 删除并将 yes 修改为 no 保存退出
2、重启sshd服务
[rootfuwu1 ~]# systemctl restart sshd
3、虚拟机2上以root尝试ssh登录虚拟机1验证
[rootfuwu2 ~]# ssh root192.168.200.100
root192.168.200.100s password:
Permission denied, please try again.
root192.168.200.100s password:
发现root用户无法登录
4、Xshell上通过root用户登录尝试虚拟机1发现也无法登录
5、恢复虚拟机1的ssh配置
[rootfuwu1 ~]# vi /etc/ssh/sshd_config 将 PermitRootLogin no 一行的 no 改回 yes保存退出
重启sshd
[rootfuwu1 ~]# systemctl restart sshd
服务器2以及xshell以root用户重新登录可以成功登录 三、配置通过密钥登录
配置虚拟机2可以通过密钥的方式远程登录虚拟机1而不需要输入密码。
1、在虚拟机2中生成密钥文件
一路回车即可
[rootfuwu2 ~]# 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:1EB1rW5VDzBfHyRi7saFwwhsVpwSiTHGyWuX1gE rootfuwu2
The keys randomart image is:
---[RSA 2048]----
| oE ..o |
| ..o.B .. |
| o.*... o.|
| o.O .o |
| . S. o..* |
| . ..|
| .oo .|
| oo. |
| oo |
----[SHA256]-----
2、将公钥文件拷贝到虚拟机1中
[rootfuwu2 ~]# ssh-copy-id root192.168.200.100
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root192.168.200.100s password: Number of key(s) added: 1Now try logging into the machine, with: ssh root192.168.200.100
and check to make sure that only the key(s) you wanted were added.
3、在虚拟机2上远程登录虚拟机1验证
[rootfuwu2 ~]# ssh root192.168.200.100
Last login: Wed Aug 17 20:40:50 2022 from 192.168.200.1
[rootfuwu1 ~]#
发现这次没有输入密码即可自动登录这就是密钥方式登录
4、Xshell配置密钥登录
先在windows上通过Xshell生成一个密钥然后把密钥的公钥部分添加到虚拟机1的相关文件中
[rootfuwu1 ~]# vi /root/.ssh/authorized_keys
然后就可以密钥登录 -----界面演示----- 四、scp远程拷贝命令演示
scp即 ssh cp 实现与远程机器之间的文件拷贝
在虚拟机2上创建一个文件a.txt并将该文件远程传输到虚拟机1的 /root/ 目录下
[rootfuwu2 ~]# touch a.txt[rootfuwu2 ~]# scp a.txt root192.168.200.100:/root/a.txt
a.txt
在虚拟机1上验证
[rootfuwu1 ~]# ll /root/ |grep a.txt
-rw-r--r--. 1 root root 0 8月 17 21:12 a.txt