简单实现ssh的无密码登陆

主机a: 192.168.211.128

主机b:192.168.211.129

现在就来实现主机b无需密码即可ssh到主机a。

1.在主机b上执行:ssh-keygen -t dsa

ubuntu@ubuntu-desktop:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):  (这里是密钥的存储路径,直接回车就行)
Enter passphrase (empty for no passphrase):输入密码,可以为空)
Enter same passphrase again: (再次输入密码,保持一致)
Your identification has been saved in /home/ubuntu/.ssh/id_rsa.
Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub.
The key fingerprint is:
18:b9:d9:af:28:ef:aa:0d:53:5a:4a:b0:b4:3f:05:b8
ubuntu@ubuntu-desktop
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|  .    .         |
|.o .  o          |
|.oo .  *         |
|.E. o.+ S        |
| ..=.    .       |
|  =o      .      |
|   +o  . .       |
|  ..o=+ .        |
+-----------------+

2.把公钥放到主机a上

scp /root/.ssh/id_dsa.pub 192.168.211.128:/root/.ssh/authorized_keys

(必须改名为authorized_keys ,否则不成功)

3.在主机b上执行:

eval `ssh-agent`

ssh-add

root@ubuntu-desktop:~# ssh-add
Enter passphrase for /root/.ssh/id_dsa:  (再次输入密码)
Identity added: /root/.ssh/id_dsa (/root/.ssh/id_dsa)

4.验证

在主机b上ssh主机a

ssh 192.168.211.128

最后,截个图给大家看看。

 

 

你可能感兴趣的:(ssh,职场,密码,登陆,休闲)