一、环境说明:

操作系统:CentOS-7-x86_64-Minimal-1611

虚拟机:VMware® Workstation 12 Pro;12.5.5 build-5234757

服务器:node1(User1),node2(User2)

二、实现内容:

node1 服务器用户 User1 可通过 SSH ,免密钥登录服务器 node2 的 User2 账户;

三、配置流程:

默认情况下,node1 上的用户 User1 想连接 node2,需要输入密码,如下:

 [User1@localhost ~]$ ssh User2@node2
The authenticity of host 'node2 (192.168.126.141)' can't be established.
ECDSA key fingerprint is 0c:f2:1d:5b:0a:ea:38:43:e7:d2:07:28:d8:05:8a:d6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2,192.168.126.141' (ECDSA) to the list of known hosts.
User2@node2's password:
Last login: Fri Feb 2 17:03:45 2018

1、现在通过用户 User1 在 node1 的 /home/User1 目录下生成一对公钥和私钥:

 [User1@localhost ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/User1/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/User1/.ssh/id_rsa.
Your public key has been saved in /home/User1/.ssh/id_rsa.pub.
The key fingerprint is:
ff:cc:0e:22:aa:79:54:d3:15:90:bd:98:2b:26:e1:35 User1@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| .+.. |
| . o |
| . + . |
| . E + . |
| . + oS. |
| + o .. |
| . o... o |
| ... . . = |
| oo. .= |
+-----------------+

2、然后将公钥上传给 node2 的 User2 用户:

 [User1@localhost ~]$ ssh-copy-id User2@node2
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
User2@node2's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'User2@node2'"
and check to make sure that only the key(s) you wanted were added.

3、登录验证成功:

说明:

1、此时 node1 上用户 User1 的私钥文件内容(id_rsa.pub)会追加到 node2 上用户 User2 的 ~/.ssh/authorized_keys 文件中:

2、还可以通过 scp 命令,将 node1 服务器上的公钥拷贝到 node2 服务器上,然后追加到 ~/.ssh/authorized_keys

 scp ~/.ssh/id_rsa.pub User2@node2:~/

3、还可以通过 cat 命令直接追加:

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

[CentOS] SSH 免密钥登录的更多相关文章

  1. linux系统ssh免密钥登录配置

    linux主机配置ssh免密钥登录,具体配置如下: 1.执行命令ssh-keygen -t rsa,生成公钥和私钥(具体步骤详见下图) 2.会在当前用户的家目录的.ssh/生成公钥和私钥, 3.执行s ...

  2. Linux机器之间SSH免密钥登录设置

    SSH免密钥登录 私钥:密钥留在本机 公钥:密钥发给其他机 hadoop01 生成密钥: ssh-keygen -t rsa (密钥存放路径:/root/.ssh) id_rsa:私钥 id_rsa. ...

  3. 014-配置SSH免密钥登录

    问题:client端需要免密钥登录服务器server如何配置?1.前提:客户端已安装openssh-client;服务端已安装openssh-server;服务器端22号端口已经打开2.需要密钥登录时 ...

  4. centos ssh 免密码登录

    最近在学习的过程中遇到这个问题: A主机和B主机: A 免密码登录B: 首先在A的 ~/.ssh 目录中 执行 ssh-keygen -t rsa 一路回车 最后生成连个文件: 将id_rsa.pub ...

  5. ssh免密钥登录一例问题

    今天遇到一个奇怪的问题,在同一机器上创建的普通用户使用 ssh-copy-id -i .ssh/id_rsa.pub root@192.168.3.254 建立与root用户的免密钥通信,结果死活还是 ...

  6. ssh免密钥登录

    说明:下文中说的 '客户端'指的是你所使用的本地机器; '服务端'指的是远程你要连接的机器; ----------------------------------------------------- ...

  7. linux配置ssh免密钥登录

    https://blog.csdn.net/xiaoyi23000/article/details/80597516 1.执行命令ssh-keygen -t rsa,生成公钥和私钥 2.会在当前用户的 ...

  8. Centos6.5之ssh免密码登录配置

    Centos6.5之ssh免密码登录配置 centos ssh 免密码登录 0.说明 这里为了方便说明问题,假设有A和B两台安装了centos6.5的主机.目标是实现A.B两台主机分别能够通过ssh免 ...

  9. 在CentOS/RHEL上设置SSH免密码登录

    本文会告诉你怎样在 CentOS/RHEL 上设置 SSH 免密码登录.自动登录配置好以后,你可以通过它使用 SSH (Secure Shell)和安全复制 (SCP)来移动文件. SSH 是开源的, ...

随机推荐

  1. Jqurey 得到url参数 getUrlParam

    Jqurey 得到url参数 getUrlParam <script type="text/javascript"> (function ($) { //扩展方法获取u ...

  2. Directory Opus(DO) 11破解版安装方法(转)

    DO11原版下载 32位:http://www.gpsoft.com.au/DScripts/download.asp?file=Opus11/DOpusInstall.exe 64位:http:// ...

  3. NOIp2017 滚粗记

    NOIp2017 滚粗记 Day0 早上 早自习的时候,班主任忽然告诉我们, 我们要参加期中考试... 这对于我们真是一个沉重的打击... 但是,管不着了 明天就死去考试了 上午 \(8:10\)到了 ...

  4. 【NOIP2013】华容道(最短路)

    题目戳我 懒得粘贴题目了..就这要凑合一下吧... 题解 反正棋盘的状态不会变的... 所以,预处理一下??? 恩,如果一个棋子要移动到某个目标位置的话, 可以看成只有空格和这个子要动呀(其他的有区别 ...

  5. MySQL配置文件

    [mysqld]datadir=/usr/local//mysql/data    #数据存放位置socket=/var/lib/mysql/mysql.sockuser=mysqllower_cas ...

  6. javascript 推箱子游戏介绍及问题

    最近没什么事情,我的一个亲戚在学校学习PHP,课程中老师让他们编写一个javascript版本的推箱子小游戏,他没什么头绪,就来问我,我当时很闲,就随口答应他包在我身上.结果真正写的时候还是花了点时间 ...

  7. 大三小学期 web前端开发的一些小经验

    1.html是页面的布局设计,就是页面上要放哪些东西,比如登录界面需要按钮,输入框等等:css是被用于使用设计部件和布局,例如哪些部件放在哪里,多宽多大,是否有边框等:js/jQuery是用于实现函数 ...

  8. jQuary学习の一の初期准备

    jQuery 的功能概括: 1.html 的元素选取 2.html的元素操作 3.html dom遍历和修改 4.js特效和动画效果 5.css操作 6.html事件操作 7.ajax异步请求方式 通 ...

  9. Android RecyclerView 滚动到中间位置

    最近看到QQ音乐的歌词每次滑动后都可以滚回到中间位置.觉得甚是神奇,打开开发者模式显示布局,发现歌词部分不是采用 android 控件的写的,应该是前端写的.于是,我想,能不能用 recyclerVi ...

  10. 01背包问题(Java实现)

    关于背包问题,百度文库上有崔添翼大神的<背包九讲>,不明的请移步查看.这里仅介绍最基本的01背包问题的实现. public class Knapsack { private final i ...