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

    你可能感兴趣的文章
    NN&DL4.7 Parameters vs Hyperparameters
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    nnU-Net 终极指南
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    no available service ‘default‘ found, please make sure registry config corre seata
    查看>>
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    查看>>
    no connection could be made because the target machine actively refused it.问题解决
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
    查看>>