博客
关于我
[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/

    你可能感兴趣的文章
    npm安装crypto-js 如何安装crypto-js, python爬虫安装加解密插件 找不到模块crypto-js python报错解决丢失crypto-js模块
    查看>>
    npm安装教程
    查看>>
    npm报错Cannot find module ‘webpack‘ Require stack
    查看>>
    npm报错Failed at the node-sass@4.14.1 postinstall script
    查看>>
    npm报错fatal: Could not read from remote repository
    查看>>
    npm报错File to import not found or unreadable: @/assets/styles/global.scss.
    查看>>
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
    查看>>
    npm版本过高问题
    查看>>
    npm的“--force“和“--legacy-peer-deps“参数
    查看>>
    npm的安装和更新---npm工作笔记002
    查看>>
    npm的常用操作---npm工作笔记003
    查看>>
    npm的常用配置项---npm工作笔记004
    查看>>
    npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
    查看>>
    npm编译报错You may need an additional loader to handle the result of these loaders
    查看>>
    npm设置淘宝镜像、升级等
    查看>>
    npm设置源地址,npm官方地址
    查看>>
    npm设置镜像如淘宝:http://npm.taobao.org/
    查看>>
    npm配置安装最新淘宝镜像,旧镜像会errror
    查看>>
    NPM酷库052:sax,按流解析XML
    查看>>