ssh技巧

ssh通过密钥private key连接服务器仍然需要输入密码的问题解决办法

ssh配置rsa类型的密钥,权限没问题的情况下,链接服务器:

ssh -i /Users/moneyslow/key/id_rsa.upload.pri upload@123.123.123.123

如果仍然需要输入密码,在服务器段可重新启用新端口进行debug拍错:

/usr/sbin/sshd -ddd -D -p 2222

客户端执行:

ssh -vvv -p 22222 -i /Users/moneyslow/key/id_rsa.upload.pri upload@123.123.123.123

会发现服务器段的错误信息:

ssh通过密钥private key连接服务器仍然需要输入密码的问题解决办法

mm_answer_keyallowed: publickey authentication: RSA key is not allowed
很显然,服务器或者是客户端有一个不支持RSA key这种密钥方式
这种情况下,以我的经验,不折腾,果断放弃rsa,重新使用更先进的密钥方式:


RSA −This is one of the most common types of SSH keys.

It uses asymmetric encryption methodology which means that it allows both encryption and decryption using separate but mathematically related keys. RSA supports various lengths including 2048-bit or 3072-bit.

DSA −Digital Signature Algorithm (DSA) is another type of asymmetric cryptography that can be used for SSH key generation. It is faster than RSA but less secure as well.

DSA keys are usually shorter and less secure than RSA keys and they are widely used for digital signatures in the US legal system.

ECDSA −Elliptic Curve Digital Signature Algorithm (ECDSA) is a newer type of asymmetric cryptography that is faster and more secure than both RSA and DSA keys.

这里选择ECDSA:

ssh-keygen -t ecdsa

重新走一遍ssh key的配置流程,基本解决问题。

另外,如果是dss的问题,参考: