Linux服务器SSH免密登录配置

三台虚拟机172.16.43.103,172.16.43.104,172.16.43.105

1、在每台虚拟机上执行命令:ssh-keygen -t rsa,执行时所有提示都一路回车跳过。执行完成后会在/root/.ssh目录生成两个文件

-rw------- 1 root root 1675 3月  30 00:49 id_rsa
-rw-r--r-- 1 root root  392 3月  30 00:49 id_rsa.pub

 

2、在每台虚拟机上创建/root/.ssh/authorized_keys文件

然后将172.16.43.103,172.16.43.104服务器上id_rsa.pub公钥内容拷贝到172.16.43.105的/root/.ssh/authorized_keys文件里

然后将172.16.43.103,172.16.43.105服务器上id_rsa.pub公钥内容拷贝到172.16.43.104的/root/.ssh/authorized_keys文件里

然后将172.16.43.104,172.16.43.105服务器上id_rsa.pub公钥内容拷贝到172.16.43.103的/root/.ssh/authorized_keys文件里

以105为例,105的authorized_keys文件内容如下:

[root@test3 .ssh]# cat authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyVe58GA83wSxS27muU4cdKmwZGPrQWp6LCcyYOlsT92mgcdWFQL/pe7lYd/HDvgObz8Vd0GRUJ7QpXIyp5oJB7S0TzBwLXd2mBjAU63LBVv2piSZPr4y+Y9XLGh4zt6joXeXkhetj4zjXvcW1HcwbguwQZ/4sMiuq+DEF14vo8myTcaRaFdhieNTaRo+/nZK7mYzkeOskMs1FSAsR2m10ko6xD4loFRQucU5+lEV5WXEP+IIyucpc4dcV1ksImyINIuh28gM2YxFDRnqPY9pngdyeD6QANof422/OPUoBpv1WEP1hzVevTLmUXhA8eJz51Mp1PWkEpA4gmwYanVSoQ== root@test2
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA5etNtOUewKgLJum52BWYTuSuRMj8c5o8eiJB2K1AbM/PENlAvyNsTBJPJZAlRnm7f3yN4NxMNO8+DuGNRG4oASrGmQklzGgOaNOqfbcIN9Na/s45uPbZdp0R2hO2kgFrWFu6BX0e52RjRhzVYb9ewMw4SH0CVOEUMo6XtK6N8sGExSaumnvZYVVS63E5NU2AWMlAy6cpe8gVtQc4Xjv0Oja7R634Nw0tBV1IkbbyvzfRo1wzF8pRMPgXcfQpXSq1KKxN4M9fG5v7oAEC8xyRhHYsdp8BxciURx8INFDOJMi3vXzLCTmCnWx2MdEUQAXp7tjtSIDe8hszRM1wtCaE3w== root@test1

 

3、在172.16.43.103上执行命令:ssh 172.16.43.104,可以看到无需指定用户,密码可直接登录到104服务器。

 

posted @ 2021-03-30 18:18  shileishmily  阅读(241)  评论(0编辑  收藏  举报