方法
- 分别在win10和Linux上生成密钥:
ssh-keygen -t rsa
win10的路径: C:\Users\用户名\.ssh\
Linux的路径: /root/.ssh
- 将win10的公钥
id_rsa.pub
传输到Linux路径下并更名为authorized_keys
# 在win10的终端,下面的IP换成自己虚拟机的IP
cd C:\Users\MengC\.ssh>
scp .\id_rsa.pub root@192.168.56.101:/root/.ssh/authorized_keys
源代码
- Linux
[root@rac1 ~]# ssh-keygen -t rsa
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:
# 直接三个回车得到一个类似这样的图
The key's randomart image is:
+---[RSA 2048]----+
| +=XOOo |
| o *=E.*.|
| . ..O.+o*|
| . +o= .+|
| S .o=...|
| .=.=oo|
| .+o+.|
| .. .|
| |
+----[SHA256]-----+
[root@rac1 ~]# cd .ssh/
[root@rac1 .ssh]# ls
id_rsa id_rsa.pub
[root@rac1 .ssh]# ls
authorized_keys id_rsa id_rsa.pub
[root@rac1 .ssh]#
- win10
PS C:\Users\MengC> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\MengC/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\MengC/.ssh/id_rsa.
Your public key has been saved in C:\Users\MengC/.ssh/id_rsaThe key
The key's randomart image is:
+---[RSA 2048]----+
| +++o |
| . . . |
| .+ . . |
| B.+ + . |
| +.B S * . . +|
| o+ E = * +o|
| o... + . + . .|
|..o.oo .. o . |
|o=+.o+++. . . |
+----[SHA256]-----+
t/.ssh/authorized_keys
PS C:\Users\MengC> cd .\.ssh\
PS C:\Users\MengC\.ssh> ls
目录: C:\Users\MengC\.ssh
Mode LastWrite Time Length Name
---- --------- ---- ------ ----
-a---- 2022/1/26 9:51 1679 id_rsa
-a---- 2022/1/26 9:51 404 id_rsa.pub
-a---- 2022/1/26 9:43 177 known_hosts
PS C:\Users\MengC\.ssh> scp .\id_rsa.pub root@192.168.56.101:/root/.ssh/authorized_keys
root@192.168.56.101's password:
id_rsa.pub 100% 404 404.2KB/s 00:00
PS C:\Users\MengC\.ssh>
使用
利用windows terminal
远程连接虚拟机
打开软件 -> 打开设置 -> 添加新的配置文件 -> 新建空配置文件
分享一下我的图标: