[CentOS] SSH 免密钥登录
一、环境说明:
操作系统: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 免密钥登录的更多相关文章
- linux系统ssh免密钥登录配置
linux主机配置ssh免密钥登录,具体配置如下: 1.执行命令ssh-keygen -t rsa,生成公钥和私钥(具体步骤详见下图) 2.会在当前用户的家目录的.ssh/生成公钥和私钥, 3.执行s ...
- Linux机器之间SSH免密钥登录设置
SSH免密钥登录 私钥:密钥留在本机 公钥:密钥发给其他机 hadoop01 生成密钥: ssh-keygen -t rsa (密钥存放路径:/root/.ssh) id_rsa:私钥 id_rsa. ...
- 014-配置SSH免密钥登录
问题:client端需要免密钥登录服务器server如何配置?1.前提:客户端已安装openssh-client;服务端已安装openssh-server;服务器端22号端口已经打开2.需要密钥登录时 ...
- centos ssh 免密码登录
最近在学习的过程中遇到这个问题: A主机和B主机: A 免密码登录B: 首先在A的 ~/.ssh 目录中 执行 ssh-keygen -t rsa 一路回车 最后生成连个文件: 将id_rsa.pub ...
- ssh免密钥登录一例问题
今天遇到一个奇怪的问题,在同一机器上创建的普通用户使用 ssh-copy-id -i .ssh/id_rsa.pub root@192.168.3.254 建立与root用户的免密钥通信,结果死活还是 ...
- ssh免密钥登录
说明:下文中说的 '客户端'指的是你所使用的本地机器; '服务端'指的是远程你要连接的机器; ----------------------------------------------------- ...
- linux配置ssh免密钥登录
https://blog.csdn.net/xiaoyi23000/article/details/80597516 1.执行命令ssh-keygen -t rsa,生成公钥和私钥 2.会在当前用户的 ...
- Centos6.5之ssh免密码登录配置
Centos6.5之ssh免密码登录配置 centos ssh 免密码登录 0.说明 这里为了方便说明问题,假设有A和B两台安装了centos6.5的主机.目标是实现A.B两台主机分别能够通过ssh免 ...
- 在CentOS/RHEL上设置SSH免密码登录
本文会告诉你怎样在 CentOS/RHEL 上设置 SSH 免密码登录.自动登录配置好以后,你可以通过它使用 SSH (Secure Shell)和安全复制 (SCP)来移动文件. SSH 是开源的, ...
随机推荐
- freemarker写select组件(五)
freemarker写select组件 1.宏定义 <#macro select id datas value="" key="" text=" ...
- CSDN博客添加量子恒道统计代码步骤
CSDN博客添加量子恒道统计代码步骤. 1. 去量子恒道网站统计 注册账户: 2. 添加已有的CSDN博客地址: 3. 添加博客后恒道代码里面会给你一个JavaScript脚本,记下里面的一串数字: ...
- maven项目转eclipse
很多国外的开源项目是用maven编译的,对于我们比较熟悉eclipse开发的童鞋来说,能转成.project是最好不过了. 很简单,装好maven后,在项目目录打开命令行,输入 mvn eclipse ...
- Excel VBA TextBox控件的滚动条不能刷新
问题:Excel中Textbox控件以及Form里的Textbox控件,当直接填充的内容很长时,滚动条不能实时刷新. 现象: 修改后: 原因: 虽然已经向Textbox的Text里设置了内容,但此时T ...
- jsTree树形菜单分类
这里我演示的jsTree是基于ABP框架 ,展示部分代码,话不多说首先看效果如: 1:引入JS <link href="/jstree/themes/default/style.css ...
- C#图解教程
初识本书是在知乎,许多网友推荐它作为 C# 入门书籍. 本书的最大特点是插图丰富,许多复杂的概念,一副插图就解释得通透明了. 本书另外一个隐藏特性是作者有着 C/C++ 经验,书中经常提到它们与 C# ...
- 初识Windows服务 C#
1.新建Windows服务 2.切换到代码视图,拷入如下代码 该服务以10S的间隔创建 d:/1.txt 文件 using System; using System.Collections.Gen ...
- javascript右键菜单分析
右键菜单 思路 1.遮蔽原来的默认右键菜单 2.新建右键菜单跟随鼠标移动 3.注意边界处的位置变化 4.自定义右键内容的具体效果 具体 这样的事件涉及到有关contextmenu事件,阻止默认事件,获 ...
- [CF908D]New Year and Arbitrary Arrangement
题面在这里 题意 给定三个数\(k,pa,pb\),每次有\(\frac{pa}{pa+pb}\)的概率往后面添加一个'\(a\)',每次有\(\frac{pb}{pa+pb}\)的概率往后面添加一个 ...
- c++程序运行时的内存分配《转》
C++中,内存分为5个区:堆.栈.自由存储区.全局/静态存储区和常量存储区. 1.栈:是由编译器在需要时自动分配,不需要时自动清除的变量存储区.通常存放局部变量.函数参数等. 2.堆:是由new分配的 ...