ssh 实现免密码登录

简介: 相互认证将要相互认证的 ip 和 hostname 做映射,并放置在各机器中[root@master ~]# cat /etc/hosts127.0.0.1 localhost localhost.

相互认证

将要相互认证的 ip 和 hostname 做映射,并放置在各机器中

[root@master ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.10 master
10.0.0.11 node01
10.0.0.12 node02

生成key

在master机器上为例,生成密钥,将公钥拷贝到node01 和 node02 上;如果要实现node01免秘钥登录别的机器,将node01 生成的公钥拷贝至各机器。

[root@master ~]# 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:2sVd/Xh8vuuUOkoy+PP1VHQvsf08JuzLCWBGyfOHQPA root@master
The key's randomart image is:
+---[RSA 2048]----+
|       ...       |
|        + .    . |
|         E    o +|
|        ..+... B+|
|        S+oo..+ O|
|       o+.. o  ==|
|      ...o o + *+|
|        ..+ =.O o|
|         .oo.*+=.|
+----[SHA256]-----+

拷贝公钥到目标机器

[root@master ~]#ssh-copy-id node01
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'node01 (10.0.0.11)' can't be established.
ECDSA key fingerprint is SHA256:0WjkfswyQXRv+zeS03AF9xLANd4uZtFo0YcY7kGiagA.
ECDSA key fingerprint is MD5:32:e0:54:7e:8c:a0:1c:59:17:7b:00:3a:71:89:e1:a4.
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
root@node01's password: 

Number of key(s) added: 1

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

问题

ECDSA key fingerprint is SHA256:ib+nKTC8u2GwAMYRC1pfxVsz2Sy+K26lPbqOZ3qvOig.
ECDSA key fingerprint is MD5:4b:4b:6f:b7:a4:81:80:20:7f:60:1e:74:27:5b:a3:c0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.33.11' (ECDSA) to the list of known hosts.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

解决方法

修改/etc/sshd_config 文件中的配置,将
PermitRootLogin 置为 yes
PubkeyAuthentication 置为 yes
PasswordAuthentication 置为 yes
之后重启ssh 服务

[root@master ~]# systemctl restart sshd
目录
相关文章
|
1月前
|
安全 Shell 网络安全
ssh配置无密码验证
ssh配置无密码验证要在SSH中配置无密码验证,您需要使用公钥验证【2月更文挑战第18天】
39 1
|
2月前
|
安全 网络协议 Linux
|
2月前
|
安全 网络协议 Shell
SSH连接密码问题:原因、表现与解决方案
SSH连接密码问题:原因、表现与解决方案
94 3
|
2月前
|
关系型数据库 网络安全 数据库
通过SSH登录OceanBase数据库需要修改用户密码,然后使用SSH客户端进行远程登录
通过SSH登录OceanBase数据库需要修改用户密码,然后使用SSH客户端进行远程登录
73 6
|
2月前
|
存储 Linux 网络安全
如何在 Linux 中删除 SSL 证书和 SSH 密码?
如何在 Linux 中删除 SSL 证书和 SSH 密码?
84 1
如何在 Linux 中删除 SSL 证书和 SSH 密码?
|
2月前
|
网络安全 数据安全/隐私保护
如何使用ssh key免密码登录服务器?
如何使用ssh key免密码登录服务器?
|
3月前
|
安全 Linux Shell
Linux服务器配置SSH免密码登录后,登录仍提示输入密码(一次真实的问题排查解决记录)
Linux服务器配置SSH免密码登录后,登录仍提示输入密码(一次真实的问题排查解决记录)
92 0
|
3月前
|
安全 Linux 网络安全
服务器设置 SSH 通过密钥登录
服务器设置 SSH 通过密钥登录
|
4月前
|
Linux 网络安全 数据安全/隐私保护
Xshell配置ssh免密码登录-公钥与私钥登录linux服务器
Xshell配置ssh免密码登录-公钥与私钥登录linux服务器
184 0
|
8月前
|
安全 Ubuntu Linux
如何在 Linux 中设置 SSH 无密码登录
如何在 Linux 中设置 SSH 无密码登录
160 0