更新时间:2022-05-07 GMT+08:00
分享

配置互信

在配置前需要两台服务器能够通过SSH互相跳转。假设需要同步的两台服务器为节点1与节点2。可以使用如下步骤进行配置。

操作步骤

  1. 使用root账号登录节点1
  2. 生成公钥私钥

    ssh-keygen -t rsa

    出现以下信息:

    Generating public/private rsa key pair.Enter file in which to save the key (/home/deven/.ssh/id_rsa): (回车)
    Enter passphrase (empty for no passphrase): (回车)
    Enter same passphrase again:(回车) 
    Your identification has been saved in /home/deven/.ssh/id_rsa.
    Your public key has been saved in /home/deven/.ssh/id_rsa.pub.
    The key fingerprint is:89:56:d6:4a:b2:6c:4a:05:............

    中间过程直接3个回车。在/root/.ssh/目录下,生成了两个文件:id_rsa 和 id_rsa.pub

  3. 将id_rsa.pub信息写入到authorized-keys中。

    cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

  4. 修改id_rsa权限。

    chmod 600 /root/.ssh/id_rsa

  5. 将anthorized-keys和id_rsa复制到节点2。

    scp /root/.ssh/authorized_keys 节点2的IP地址:/root/.ssh/

    输入命令后会有回显询问是否需要连接,输入“yes”之后,再输入节点2的密码,即可将文件复制到节点2。

    scp /root/.ssh/id_rsa 节点2的IP地址:/root/.ssh/

  6. 验证跳转是否成功。

相关文档