白桦林

秋空雁度青天远,疏树蝉鸣白露寒

导航

SSH通过密钥登陆

A服务器上操作
ssh-keygen  -t rsa/dsa 后面所带参数rsa/dsa为加密方式,默认为dsa
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
dc:15:f9:6d:f3:d5:a7:3f:64:9d:dd:7e:f4:38:52:e3 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|            ..   |
|            ..   |
|            .. ..|
|       . . .  ..*|
|        S .    oX|
|              ++*|
|             oo*.|
|            . E.=|
|             . .o|
+-----------------+

[root@localhost .ssh]# ll
total 8
-rw-------. 1 root root 1766 Aug 28 04:37 id_rsa
-rw-r--r--. 1 root root  408 Aug 28 04:37 id_rsa.pub
B服务器上操作

将id_rsa.pub复制到B 目录位置在 /root/.ssh中,如果B中没有这个.ssh目录,需要创建,并且保证权限不能大于711
在/root/.ssh中创建文件 authorized_keys, 执行命令cat /root/.ssh/id_rsa.pub > authorized_keys

然后在A上执行 ssh B服务器地址 或者 ssh -i ./id_rsa root@B服务器地址 即可使用密钥登陆B  

 

posted on 2018-09-30 15:33  走进黑夜  阅读(242)  评论(0)    收藏  举报