Red Hat Enterprise Linux 7 高薪入门pdf下载
准备3台Linux系统电脑,确定每个电脑上安装了ssh
ssh</a>无密码登录要使用公钥余私钥,Linux下可以使用ssh-keygen生成公钥/私钥对。
现在确认能否不输入口令就用ssh登录localhost:
[root@master /]# ssh localhost
如果必须要密码登录,那么现在修改如下
-P表示密码,-P '' 就表示空密码。
生成.ssh目录,.ssh下面有id_dsa和id_dsa.pub
[root@master /]# ssh-keygen -t dsa -P ''
回车之后返回如下:
Generating public/private dsa key pair.
Enter file in which to save the key(/root/.ssh/id_dsa): //这里敲击回车
Created directory '/root/.ssh'.
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
35:78:92:cf:17:2b:53:ae:79:9c:fe:56:f1:d0:50:b1 root@master
The key's randomart image is:
+--[ DSA 1024]----+
| oo|
| o . .|
| + + o E |
| * + o...|
| S = + .o|
| B . o|
| o + . |
| o . |
| .o. |
+-----------------+
因为我现在用的是root账户,所以秘钥文件保存到了/root/.ssh/目录内,可以使用命令查看,命令是:
[root@master /]# ls /root/.ssh/
在其他2台电脑上重复上面的操作
接下来要做的事情是在3台机器的/root/.ssh/目录下都存入一个内容相同的文件,文件名称叫authorized_keys,文件内容是我们刚才为3台机器生成的公钥。为了方便,我下面的步骤是先在其中一台上生成authorized_keys文件,然后把3台机器刚才生成的公钥内容加入到这个这一台电脑上的authorized_keys文件里,然后在将这个authorized_keys文件复制到其他两台电脑上面。
[root@master /]# touch /root/.ssh/authorized_keys
其次将master机器上的/root/.ssh/id_rsa.pub文件内容,slave1上的/root/.ssh/id_rsa.pub文件内容,slave2上的/root/.ssh/id_rsa.pub文件内容复制到这个authorized_keys文件中,复制的方法很多了,可以用cat命令和vim命令结合来弄,也可以直接把这3台机器上的/root/.ssh/id_rsa.pub文件下载到本地,在本地将authorized_keys文件编辑好在上载到这3台机器上。
master机器上我的/root/.ssh/id_rsa.pub内容是:
ssh-dss AAAAB3NzaC1kc3MAAACBAOKWeOpwimwZxTZmL3Vpntnhc8iUgOI+zwszgmQKeiz7elRUKElvRZ0k5IykmnrMPmqjiaARfro4tPS3opScGkxLE/7a2MoBX+2nglAb/UuSwXJAhyhtOEdZxQOkLLkuOeRJKw8i9h+j5TYncZ5lnrOZNzEpYUn+Z9d1wo8zPtvHAAAAFQCcBbx7CBzxgh+h/8THGB2aWEd23wAAAIAfE1tgIBcmyMQzqeEmeeoPYdxyx/HiNG5fQI1vP0Do4TgNf9RxsRDILzsN5HJYYJVLlDswJK0YLRlNyEXUHIBUQT0dHfVJFHguuYApThOOBUpKdxiNloTNwOdvWkvguQ4saqJs537m+j7IWavdC2gdW7P8XYDPi2lMwAdY65piAAAAAIBwSSUnrq2VCKXA+op6FXYAr5F4707iXy9hV7Jocmc7pbitUBN5FOmvVXZ7U/1k4NgUH0qCnHzx7zGVTXfWLXh68cXfiXGcdO3OMMikxI58CChGiju378t67ByBFuWq53gV6i287XM+NtiMS8pHozv/xZ039j0h8k9kh7QpHeO42A== root@master
slave1机器上我的/root/.ssh/id_rsa.pub内容是:
ssh-dss AAAAB3NzaC1kc3MAAACBAPloSJKoUkgswfrujiW3nJbUqDBAkbEnq7GlAvtN3MMJpKRb2WTOynZfKQ/vFr/vJonFLDCnnuXDtNJ73dbHKuSMxZEwrpsMen+jXU0vgbwhh83dl70Hn+QT191T3L52gJ6lZporDlCNfLMBwORHfdqwPQo42uc+g9lPgsobQeKTAAAAFQC4vXatmetNzV6ovIMKxPcJZ8aITwAAAIEAz6rPEHfQ7MTf19MDAvVmEVtQXFzJgANxnDZtH/5fdtNnZ5AbAMjqIshDvh9DGKtEZOoC3ngbz9WVO/AxPR0HJRa1tmy8pmKJQybc9IwBL6kcb26lZigc+BQoFlFQclljogvJdCAn6kph+tkJ0FsTVH7dxGnbTmEoup21Tk3QOEgAAACAE1m8IpM48C7ESiySbPpqcg0HZX57SHgsDFJJfHG6epLwjPG2qIBhiCHR/mbj6urMLMLQgHhBUriMy3G5ZvwGGfZuUkupTvktrRaIrR65ZVl33zAn5wS0JChGYyukaV3BB7f8clUJRghFo4SmjHuEl66W6TZ2Qqaz5XFJLkaRI0g= root@slave1
slave2机器上我的/root/.ssh/id_rsa.pub内容是:
ssh-dss AAAAB3NzaC1kc3MAAACBAIdNx0ge4ybHQ6xttbh/8uONS0M4o6b3ZmMI5csiElDO2fydxt+N1qte0yIKgxc58snQAXI83nWlDuPRT2HIuwhnTTkbjpfgllD/5Yn/7UtdFp89c+TaMxDMI+WRQqAivGaBCv7EofXU17pEo6tNeiVObjUPQM+K1j+WKdXrgA+JAAAAFQDqRzP211VqNc8XYg+8KVPj+qtT/wAAAIEAhsU1q+8pHuCx+waLIOCSuEvXe5irGze2rtkWCz9ZjthMSeBNhqEprIq3pj0x4aZ3JLWmH9HwurBDpegqx2wuu3L+2ysnfIGa0nLP4Bb6bkzK1FvwIfl/k8EUpmGaKT+HQHh6Ki+okeJVgF0m9KhL1aBzaLS6v42dxI8HbiJ4gFEAAACAAyC7TyJ48xMgHm1emRHS5h69l8TmDoQN33JHcKoBL/W9In4wNMLPEvIsgXqxm/vy+SGJA8YDP+1mZ9WuA86ax0NigWSELQfViyoPdSVieTTqs9WksatG2ZtdjVKS/lbxXFQKFnH71L0BF6zEzPii4psLKz8K6ztLsmKPRUM1pO0= root@slave2
合并之后,我的master机器上的/root/.ssh/authorized_keys文件内容是:
ssh-dss AAAAB3NzaC1kc3MAAACBAOKWeOpwimwZxTZmL3Vpntnhc8iUgOI+zwszgmQKeiz7elRUKElvRZ0k5IykmnrMPmqjiaARfro4tPS3opScGkxLE/7a2MoBX+2nglAb/UuSwXJAhyhtOEdZxQOkLLkuOeRJKw8i9h+j5TYncZ5lnrOZNzEpYUn+Z9d1wo8zPtvHAAAAFQCcBbx7CBzxgh+h/8THGB2aWEd23wAAAIAfE1tgIBcmyMQzqeEmeeoPYdxyx/HiNG5fQI1vP0Do4TgNf9RxsRDILzsN5HJYYJVLlDswJK0YLRlNyEXUHIBUQT0dHfVJFH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IOCSuEvXe5irGze2rtkWCz9ZjthMSeBNhqEprIq3pj0x4aZ3JLWmH9HwurBDpegqx2wuu3L+2ysnfIGa0nLP4Bb6bkzK1FvwIfl/k8EUpmGaKT+HQHh6Ki+okeJVgF0m9KhL1aBzaLS6v42dxI8HbiJ4gFEAAACAAyC7TyJ48xMgHm1emRHS5h69l8TmDoQN33JHcKoBL/W9In4wNMLPEvIsgXqxm/vy+SGJA8YDP+1mZ9WuA86ax0NigWSELQfViyoPdSVieTTqs9WksatG2ZtdjVKS/lbxXFQKFnH71L0BF6zEzPii4psLKz8K6ztLsmKPRUM1pO0= root@slave2
将authorized_keys文件复制到其他机器
master机器的/root/.ssh/目录下已经有authorized_keys这个文件了,该文件的内容也已经OK了,接下来要将该文件复制到slave1机器的/root/.ssh/和slave2机器的/root/.ssh/。
复制的方法有很多,最简单的就是用SecureFX可视化工具操作吧。
复制完成后,可以看到三台机器的/root/.ssh目录下都有了这样的文件
三台机器的/root/.ssh都有同名的文件,但是只有authorized_keys文件的内容是相同的。
master机器的客户端分别通过ssh登录slave1和slave2试一试发现成功了,无密码登录
ssh slave1;(如果hostname没有修改的话就使用ip登录 :ssh 192.168.31.79)
ssh slave2;(如果hostname没有修改的话就使用ip登录 :ssh 192.168.31.206)
记住每次登录后,通过exit;命令退出,否则你的后续命令是在另外一台机器上执行的。
转载请注明:谷谷点程序 » Linux centos 免密码ssh设置