除了经过交互式的方式输入用户名和密码觉得,SSH中还能够经过一种“公私钥”的方式进行登陆,具体的原理为:ubuntu
首先在客户端上建立一对公私钥 (公钥文件:~/.ssh/id_rsa.pub; 私钥文件:~/.ssh/id_rsa)服务器
而后把公钥放到服务器上(~/.ssh/authorized_keys), 本身保留好私钥dom
当ssh登陆时,ssh程序会发送私钥去和服务器上的公钥作匹配.若是匹配成功就能够登陆了ssh
具体的实现方法以下:
user@ubuntu :~$ ssh-keygen -t rsa -P “”
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Created directory ‘/home/user/.ssh’.
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
9b:82:ea:58:b4:e0:35:d7:ff:19:66:a6:ef:ae:0e:d2 hadoop@ubuntu
The key’s randomart image is:
[...snipp...]ide
user@ubuntu :~$ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys oop
主要就是红色的命令,一个是生成公私钥对,类型是rsa,固然也能够是dsa啥的。而后第二条命令就是把公钥放到受信公钥文件里。这个时候使用 spa
ssh user@localhost .net
就能够直接登陆不用再输入密码了。固然配置多台机器用scp搞一下就成,这里我就不详说了。 ip