• 多个服务器之间免密登录


    多个服务器之间免密登录

    免密登录流程

    A服务器 B服务器 生产密钥对 拷贝公钥 SSH访问B(数据用私钥A加密) 去授权key中查找A的公钥并解密数据 采用A公钥加密数据返回A 用A的私钥解密数据 A服务器 B服务器

    操作流程

    生成公钥和私钥

    使用ssh-keygen -t rsa生成秘钥

    输出结果

    使用命令会让你设置保存地址和私钥密码这里需要直接回车使用默认和空密码

    [root@localhost102 data]# ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): 
    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:
    SHA256:sq************************************tDm root@localhost102
    The key's randomart image is:
    ***************************************************
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    拷贝密钥

    直接使用ssh-copy-id拷贝秘钥

    输出结果

    [root@localhost102 data]# ssh-copy-id localhost103
    /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
    /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
    /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
    root@localhost103's password: 
    
    Number of key(s) added: 1
    
    Now try logging into the machine, with:   "ssh 'localhost103'"
    and check to make sure that only the key(s) you wanted were added.
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    使用ssh登录其他服务器

    这样就可以使用ssh免密登录其他服务器了

    [root@test102 ~]# ssh test103
    Last login: Fri Sep 16 08:16:23 2022 from 192.168.65.60
    [root@localhost103 ~]# 
    
    • 1
    • 2
    • 3

    .ssh文件夹内容

    shh包含以下文件

    [root@test102 ~]# ll .ssh/
    总用量 16
    -rw-------. 1 root root  798 915 15:53 authorized_keys
    -rw-------. 1 root root 1679 915 15:25 id_rsa
    -rw-r--r--. 1 root root  399 915 15:25 id_rsa.pub
    -rw-r--r--. 1 root root  736 915 15:51 known_hosts
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    文件名说明
    id_rsa生成的私钥
    id_rsa.pub生成的公钥
    authorized_keys存放授权过的无密登录服务器公钥
    known_hosts记录ssh访问过计算机的公钥(public key)
  • 相关阅读:
    RT-Thread 中断管理学习(二)
    Python 3D建模指南【numpy-stl | pymesh | pytorch3d | solidpython | pyvista】
    2017年亚太杯APMCM数学建模大赛B题喷雾轨迹规划问题求解全过程文档及程序
    第二张微服务的调用与注册
    智安网络|揭秘安全测试和渗透测试的异同点
    【原创】使用Golang的电商搜索技术架构实现
    Java学习——正则表达式
    [山东科技大学OJ]1490 Problem F: 该按哪些键
    LLM在text2sql上的应用
    SpringBoot自动配置
  • 原文地址:https://blog.csdn.net/qq330983778/article/details/126883504