博客
关于我
[CentOS] SSH 免密钥登录
阅读量:451 次
发布时间:2019-03-06

本文共 2270 字,大约阅读时间需要 7 分钟。

一、环境说明:

操作系统: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,需要输入密码,如下:

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

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

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

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

1 [User1@localhost ~]$ ssh-copy-id User2@node2  2 /bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed  3 /bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys  4 User2@node2's password:  5 ​  6 Number of key(s) added: 1  7 ​  8 Now try logging into the machine, with:   "ssh 'User2@node2'"  9 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

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

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

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

转载地址:http://kgmyz.baihongyu.com/

你可能感兴趣的文章
Mac book pro打开docker出现The data couldn’t be read because it is missing
查看>>
MAC M1大数据0-1成神篇-25 hadoop高可用搭建
查看>>
mac mysql 进程_Mac平台下启动MySQL到完全终止MySQL----终端八步走
查看>>
Mac OS 12.0.1 如何安装柯美287打印机驱动,刷卡打印
查看>>
MangoDB4.0版本的安装与配置
查看>>
Manjaro 24.1 “Xahea” 发布!具有 KDE Plasma 6.1.5、GNOME 46 和最新的内核增强功能
查看>>
mapping文件目录生成修改
查看>>
MapReduce程序依赖的jar包
查看>>
mariadb multi-source replication(mariadb多主复制)
查看>>
MariaDB的简单使用
查看>>
MaterialForm对tab页进行隐藏
查看>>
Member var and Static var.
查看>>
memcached高速缓存学习笔记001---memcached介绍和安装以及基本使用
查看>>
memcached高速缓存学习笔记003---利用JAVA程序操作memcached crud操作
查看>>
Memcached:Node.js 高性能缓存解决方案
查看>>
memcache、redis原理对比
查看>>
memset初始化高维数组为-1/0
查看>>
Metasploit CGI网关接口渗透测试实战
查看>>
Metasploit Web服务器渗透测试实战
查看>>
MFC模态对话框和非模态对话框
查看>>