加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

每天1个Linux技巧:centos7免密码登录ssh

发布时间:2020-12-14 00:01:40 所属栏目:Linux 来源:网络整理
导读:1、为什么要面密码登录ssh呢 第一,方便使用 第二,在云环境中,新加入的主机,要实现自动部署,则要由控制节点进行免密码管理,比如ceph中新节点的加入。 2、免密码登录的原理是什么呢 ssh登录有两种方式,密码和密钥文件,既然免密码,那么可以使用密钥文
1、为什么要面密码登录ssh呢
第一,方便使用
第二,在云环境中,新加入的主机,要实现自动部署,则要由控制节点进行免密码管理,比如ceph中新节点的加入。

2、免密码登录的原理是什么呢
ssh登录有两种方式,密码和密钥文件,既然免密码,那么可以使用密钥文件来实现登录。

3、那么如何实现呢
在这里,我们有两台服务器。
server01 ,地址是192.168.0.131
server02, 地址是192.168.0.132
我们经过如下几步,可实现server01免密码登录server02

第一步
在server01,创建密钥对,只有一条命令,后面直接回车就好

[[email?protected] ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh‘.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:OY18ZQDBLOgxHv2fpKwEWT7m6iLtDH5mKs6/7wqxNiE [email?protected]
The key‘s randomart image is:
+---[RSA 2048]----+
| o ooo. |
| = + o . |
| o B o o |
| = +..+.o |
|Eo + oS+o. |
|. + o ooo |
|. o . |
|
o=+. . |
|oBO**o |
+----[SHA256]-----+

第二步,将产生的公钥,发送到目标主机,这里暂时还要输入一次密码
[[email?protected] ~]# ssh-copy-id -i [email?protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host ‘192.168.0.132 (192.168.0.132)‘ can‘t be established.
ECDSA key fingerprint is SHA256:sXdoFk4lfiKs2dlk2QNwbxzWZbKEchhyoYRKcFqnjkY.
ECDSA key fingerprint is MD5:9b:5f:c7:28:ac:3b:9c:6d:00:25:49:91:62:60:b7:b6.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s),to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email?protected]‘s password:

Number of key(s) added: 1

Now try logging into the machine,with: "ssh ‘[email?protected]‘"
and check to make sure that only the key(s) you wanted were added.

第三步:测试,已经可以免密码登录server02主机了
[[email?protected] ~]# ssh [email?protected]
Last login: Sun Aug 11 10:02:48 2019
[[email?protected] ~]#

是不是很容易

更多学习资料请关注微信18198518349(个人号)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读