Sshd
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:
是否可以讓伺服器接受 EITHER 作為身份驗證機制?
(是的,公鑰被複製到~/.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
通常
sshd
確實允許公鑰身份驗證、密碼身份驗證和您啟用的其他身份驗證。從您的輸出中,您可以看到首先嘗試了 GSSAPI,但沒有成功。接下來提供了公鑰,但沒有被接受,最後密碼驗證要求您輸入密碼。如果您輸入了錯誤的密碼(或者該帳戶的登錄被禁用),它將失敗,您將一無所有。儘管您已將公鑰上傳到
~/.ssh/authorized_keys
文件中,但這還不足以讓密鑰身份驗證正常工作。該sshd
服務的權限也相當嚴格。目錄~/.ssh
的模式應該是 700,文件的模式應該是 600。目錄的所有者~/.ssh
應該是使用者本身,而不是 root 或其他任何人。