博客
关于我
[CentOS] SSH 免密钥登录
阅读量:451 次
发布时间:2019-03-06

本文共 943 字,大约阅读时间需要 3 分钟。

SSH免密钥登录配置指南

环境说明

  • 操作系统:CentOS-7-x86_64-Minimal-1611
  • 虚拟机:VMware® Workstation 12 Pro;12.5.5 build-5234757
  • 服务器:node1(User1),node2(User2)

在本文中,我们将指导User1如何通过SSH免密钥登录到node2服务器的User2账户。


实现内容

User1可以通过以下方式登录到node2的User2账户:

[root@localhost ~]# ssh User2@node2

配置步骤

为了实现User1的免密钥登录,我们需要执行以下操作:

  • 生成SSH公钥和私钥

    在User1的主机上,使用以下命令生成一对RSA公钥和私钥:

    ssh-keygen -t rsa
    • 生成的私钥文件位于~/.ssh/id_rsa
    • 公钥文件位于~/.ssh/id_rsa.pub
  • 将公钥上传到node2服务器

    使用ssh-copy-id命令将User1的公钥添加到node2的User2账户中:

    ssh-copy-id User2@node2
    • 这将将User1的公钥自动添加到node2的~/.ssh/authorized_keys文件中。
  • 验证登录

    现在,User1可以使用生成的私钥文件进行免密钥登录:

    ssh -i ~/.ssh/id_rsa User2@node2

  • 配置说明

    • 步骤1:在User1的/home/User1目录下生成公钥和私钥,私钥文件名为id_rsa.pub
    • 步骤2:通过ssh-copy-id命令,将公钥文件传输到node2的User2账户,并添加到~/.ssh/authorized_keys文件中。
    • 步骤3:使用私钥文件登录到node2服务器。

    其他方法

    • 通过SCP命令上传公钥

      scp ~/.ssh/id_rsa.pub User2@node2:~
    • 通过CAT命令追加到authorized_keys文件

      cat ~/.ssh/id_rsa.pub | ssh -P 22 User2@node2 'cat >> ~/.ssh/authorized_keys'

    通过以上步骤,您可以轻松实现User1到node2的免密钥登录,提升工作效率。

    转载地址:http://kgmyz.baihongyu.com/

    你可能感兴趣的文章
    Notepad ++ 安装与配置教程(非常详细)从零基础入门到精通,看完这一篇就够了
    查看>>
    Notepad++在线和离线安装JSON格式化插件
    查看>>
    notepad++最详情汇总
    查看>>
    notepad如何自动对齐_notepad++怎么自动排版
    查看>>
    Notification 使用详解(很全
    查看>>
    NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
    查看>>
    Now trying to drop the old temporary tablespace, the session hangs.
    查看>>
    nowcoder—Beauty of Trees
    查看>>
    np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
    查看>>
    np.power的使用
    查看>>
    NPM 2FA双重认证的设置方法
    查看>>
    npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
    查看>>
    npm build报错Cannot find module ‘webpack‘解决方法
    查看>>
    npm ERR! ERESOLVE could not resolve报错
    查看>>
    npm ERR! fatal: unable to connect to github.com:
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
    查看>>
    npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
    查看>>
    npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
    查看>>
    npm install CERT_HAS_EXPIRED解决方法
    查看>>
    npm install digital envelope routines::unsupported解决方法
    查看>>