集群间 ssh 互信免密码登录失败处理

一、问题描述

某次GreePlum集群免密配置过程中,需要使用普通用户实现ssh免密登录,前方反馈root用户已可完成免密登录,但普通用户同样配置,未生效,提示需输入密码才可以。
在这里插入图片描述
现场环境:
在这里插入图片描述

二、问题分析处理

2.1、开启debug模式/详细信息模式调试

在这里插入图片描述
如上图所示,ssh客户端发送秘钥后,未被服务端接受,导致秘钥信任失败,报错:we did not send a packet, disable method;采用passwoud模式进行新的认证通信。

2.2、sshd服务的开启调试模式

服务的启动一个调试模式进程:/usr/sbin/sshd -d -p 2222

客户端重新发起这个对2222的连接,观察服务侧信息:

在这里插入图片描述
在这里插入图片描述
如上图所示,显示客户侧用户的公钥文件权限有问题;正常的输出如下:
在这里插入图片描述
查询相关资料显示,可尝试: Check the permissions on your home directory, .ssh directory, and the authorized_keys file: If your ssh server is running with ‘StrictModes on’, it will refuse to use your public keys in the ~/.ssh/authorized_keys file. Your home directory should be writable only by you, ~/.ssh should be 700, and authorized_keys should be 600.

检查家目录秘钥目录权限:

发现~/.ssh/authorized_keys默认权限为664,其他权限正常,修改authorized_keys权限为600后,重试,ssh免密通过。
在这里插入图片描述

验证如下:
在这里插入图片描述
在这里插入图片描述

三、附录

3.1 SSH public key authentication problems 分析思路

Getting more debug info when connecting with your ssh client: Add a ‘-v’ option to your ssh command (e.g. ssh chuyeow@remotehost -v -v -v). Add more ‘-v’ for more detailed debug (you can do up to ‘-v -v -v’ I think).
Debugging on the remote host by running sshd in debug mode: Run ‘/usr/sbin/sshd -d -p 2222′ on the remote host and connect to it. ‘2222′ here is the port number of the sshd process you started on the remote host.
tail the authentication log: Run ‘tail -f /var/log/auth.log’ on the remotehost. You can watch the log as you try to connect via SSH with your key.
Make sure your ssh key agent is running: Do a ‘ps aux|grep ssh-agent’. Make sure your key agent is running. If you’re not using ssh-agent (I like keychain from Gentoo, or SSHKeyChain for Mac OS X), do whatever you have to do to ensure that your keychain is running.
Make sure your private key is added to the ssh key agent: Do a ’ssh-add -l’ to check that ssh-agent has your key. Likewise, if you are using something else, check your keychain application has your private key.
Check the permissions on your home directory, .ssh directory, and the authorized_keys file: If your ssh server is running with ‘StrictModes on’, it will refuse to use your public keys in the ~/.ssh/authorized_keys file. Your home directory should be writable only by you, ~/.ssh should be 700, and authorized_keys should be 600.

3.2 ssh加解密过程

在这里插入图片描述

1.客户端和服务器建立 SSH 连接,并使用 Diffie-Helman密钥交换算法协商出一个对称密钥;
2.客户惴使用协商出的对称秘钥对要发送的数据进行加密,然后发送给服务器;
3.服务器接收到加密的数据,使用协商出的对称密钥进行解密,并进行相应的处理;
4.服务器将要发送的数据使用协商出的对称秘钥进行加密,然后发送给客户端。
5.客户端接收到加密的数据,使用协商出的对称密钥进行解密,并进行相应的处理。

数据加密算法通常可以分为三类:对称加密;非对称加密;单向加密。

对称算法:所谓对称加密算法就是加密和解密使用同一个密钥。其基本算法有DES、3DES、AES等。特性:加密、解密使用同一个密钥;将原始数据分割成固定大小的块,逐个进行加密。缺陷:密钥过多;密钥分发。

非对称算法:密钥是成对出现。实现算法有RSA, DSA, ELGama等。公钥(pubkey):公开给所有人;私钥(secret key):自己留存,必须保证其私密性。特点:用公钥加密的数据,只能使用与之配对儿的私钥解密;反之亦然。其主要应用场景有:

数字签名:主要在于让接收方确认发送方身份;

密钥交换:发送方用对方的公钥加密一个对称密钥,并发送给对方;

数据加密:由于加密数据时间缓慢,一般不用来加密数据。

单向:其基本算法有:MD5,SHA1等。特点:只能解密,不能解密;可用于提取数据指纹;定长输出、雪崩效应(即数据内容的一丁点改变,可能造成输出结果的巨大变化)。一般用于提取文件的特征码,文件数据的微小改变会造成雪崩效应。

#加密
openssl enc -des3 -a -salt -in a.txt -out txt.file
#解密
openssl enc -d -des3 -a -salt -in txt.file -out a2.txt

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/ximenjianxue/article/details/131113588