0x01 客户端生成公私钥
$ ssh-keygen
一直按回车即可,生成后会在用户目录下有个 .ssh 的目录,其中包含公钥和私钥
确保客户端,也就是本机已经生成对应密钥,如果没生成,需要先生成
0x02 上传公钥到服务器
$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.55.37.187
运行后输入密码,然后提示一下信息代表成功
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.55.37.187'"
and check to make sure that only the key(s) you wanted were added.
此时就可以在服务器下看到对应的公钥
[root@VM]$ cat ~/.ssh/authorized_keys
0x03 测试
$ ssh root@192.55.37.187
运行后成功免密登陆