zoukankan      html  css  js  c++  java
  • Linux ssh 不需要输入密码的方法

    采用证书的方法可以解决ssh不需要输入密码的问题。

    本文采用CentOS的操作系统,创建SSH的key,并在两台或多台机器间实现信任。从而实现SSH登录不需要输入密码的功能。

    首先,在一台机器上创建SSH Key:

    [root@mysql-ha2 ~]# 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:

    e1:9b:9a:b8:4d:ea:2c:e7:0c:49:bd:a7:47:fa:b4:4b root@mysql-ha2

    The key's randomart image is:

    +--[ RSA 2048]----+

    |                 |

    |                 |

    |        .        |

    |   .   . .       |

    |  . .   S        |

    | . . ..  o       |

    |  o .oE o        |

    |  .+oX.+         |

    |   =X+B.         |

    +-----------------+

    此时可以在/root/.ssh目录下看到两个文件:

    -rw-------. 1 root root 1675 Dec  5 05:02 id_rsa

    -rw-r--r--. 1 root root  396 Dec  5 05:02 id_rsa.pub

    复制Key到另外一台机器上,使登录这台机器不输入密码:

    [root@mysql-ha2 .ssh]# ssh-copy-id -i id_rsa.pub root@10.1.1.4

    测试,发现登录ssh 10.1.1.4不需要密码。

     

    把id_rsa和id_rsa.pub复制到10.1.1.4上,在10.1.1.4上做同样的ssh-copy-id的动作,可以使双向ssh登录不需要密码。

     

    且采用的是相同的ssh key。

  • 相关阅读:
    effective c++ 笔记 (30-31)
    设计模式 笔记 装饰模式 Decorator
    设计模式 笔记 组合模式 Composite
    设计模式 笔记 外观模式 Facade
    effective c++ 笔记 (26-29)
    设计模式 笔记 桥接模式 Bridge
    设计模式 笔记 适配器模式 Adapter
    算法导论 第二章作业
    设计模式 创建型模式实践
    设计模式 笔记 单例模式 Singleton
  • 原文地址:https://www.cnblogs.com/hengwei/p/5021411.html
Copyright © 2011-2022 走看看