[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 是开源的, ...
随机推荐
- 各种HTML锚点跳转方式
1 js控制锚点跳转 <a name="anchor"></a> location.hash="anchor"; 不只有a其他元素也可以 ...
- html点小图看大图最快捷的方法
方法一: <td> <a href="{$vo.show_img}" target="_blank"><img style=&qu ...
- 登录对话框(窗体程序)--JAVA基础
1.用到的JFrame(框架)类对象(这里设JFrame类对象是frame)的方法有: frame.add(); 添加组件到frame框架中 frame.setVisible(); 设置框架是否可见 ...
- H5 EventSource 实现web页面推送功能demo
/** * H5 EventSource 实现web页面推送功能demo */ var serverData,statusDiv; var SERVER_URL = "index.php&q ...
- Luogu P1410 子序列
题目大意: 给定一个长度为\(N\)(\(N\)为偶数)的序列,] 问能否将其划分为两个长度为\(\frac{N}{2}\)的严格递增子序列, 输入一共有\(50\)组数据,每组数据保证\(N \le ...
- 【BZOJ2154】Crash的数字表格(莫比乌斯反演)
[BZOJ2154]Crash的数字表格(莫比乌斯反演) 题面 BZOJ 简化题意: 给定\(n,m\) 求\[\sum_{i=1}^n\sum_{j=1}^mlcm(i,j)\] 题解 以下的一切都 ...
- [BZOJ1004] [HNOI2008] Cards (Polya定理)
Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有多少种染色方案,Sun很快就给出了答案.进一步,小春要求染出Sr张红 ...
- [BZOJ2733] [HNOI2012] 永无乡 (splay启发式合并)
Description 永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示.某些岛之间由巨大的桥连接,通过桥可以 ...
- 比较工具diif-vimdiff-windows比较工具详解
以文件形式比较: # diff <变动前的文件> <变动后的文件> 以表格形式比较: #vimdiff FILE_LEFT FILE_RIGHT 或 # vim -d FILE ...
- 自言自语WEB前端面试题(二)
今天换道题,新鲜出炉的 var Model=function(){ this.name='lilei'; this.age=20; } Model.prototype.say=function(){ ...