opensshd / openssh - 允许密钥对或密码

opensshd / openssh - 允许密钥对或密码

我想配置 sshd 以允许用户使用密钥对进行身份验证,然后回退到密码身份验证。但我正在努力从手册页/ sshd_config 文件中的信息中实现这一点。

我的 sshd_config:

Protocol 2
SyslogFacility AUTHPRIV
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
UsePAM yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL
X11Forwarding yes
Subsystem       sftp    /usr/libexec/openssh/sftp-server

当我连接时,看起来好像正在发送私钥 - 但仍然提示我输入密码:

[colinm@server bin]$ ssh -v colinm@dev-server
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to dev-server [10.168.172.81] port 22.
debug1: Connection established.
debug1: identity file /home/colinm/.ssh/identity type -1
debug1: identity file /home/colinm/.ssh/id_rsa type 1
debug1: identity file /home/colinm/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'dev-server' is known and matches the RSA host key.
debug1: Found key in /home/colinm/.ssh/known_hosts:10
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Next authentication method: publickey
debug1: Trying private key: /home/colinm/.ssh/identity
debug1: Offering public key: /home/colinm/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Trying private key: /home/colinm/.ssh/id_dsa
debug1: Next authentication method: password
colinm@dev-server's password:

是否有可能让服务器接受任一作为身份验证机制?

(是的,公钥被复制到〜/.ssh/authorized_keys,并且我使用此配置重新启动了sshd)。

更多调试显示密钥对没有失败:

...
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/colinm/.ssh/identity
debug3: no such identity: /home/colinm/.ssh/identity
debug1: Offering public key: /home/colinm/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Trying private key: /home/colinm/.ssh/id_dsa
debug3: no such identity: /home/colinm/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password

答案1

通常sshd允许公钥身份验证、密码身份验证以及您已启用的其他身份验证。从输出中您可以看到首先尝试了 GSSAPI,但没有成功。接下来提供公钥,但未被接受,最后密码身份验证要求您输入密码。如果您输入错误的密码(或者该帐户的登录被禁用),它将失败,您将一无所获。

尽管您已将公钥上传到~/.ssh/authorized_keys文件中,但这还不足以使密钥身份验证正常工作。该sshd服务对权限也相当严格。目录的~/.ssh模式应为 700,文件的模式应为 600。目录的所有者~/.ssh应该是用户本身,而不是 root 或其他任何人。

相关内容