1

I would like to configure my sshd to allow users to authenticate with a keypair, then fallback to password authentication. But I'm struggling to achieve that from the information in the man pages / sshd_config file.

My 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

When I connect, it looks like the private key is being sent - but I still get prompted for a password:

[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:

Is it possible to have a server accepting EITHER as an authentication mechanism?

(yes, the public key is copied to ~/.ssh/authorized_keys, and I restarted the sshd with this configuration).

More debugging shows no failure with the key pair:

...
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
    it is a default behaviour: You see: debug1: Authentications that can continue: publickey,gssapi-with-mic,password. The reason for rejecting the key can be found in the server log or some hint can be found also in more verbose log using -vvv – Jakuje Aug 28 '15 at 12:19
4

Normally sshd does allow either public key authentication, password authentication and the others you have enabled. From your output you can see that GSSAPI is tried first, but that did not succeed. Next the public keys are offered but they were not accepted and finally the password authentication asks you for a password. If you enter a wrong password (or the login is disabled for that account) it will fail to, leaving you with nothing.

Although you have uploaded the public key into the ~/.ssh/authorized_keys file this is not enough to get key authentication to work. The sshd service is rather strict in permissions too. The directory ~/.ssh should have mode 700 and the files should have mode 600. The owner of the directory ~/.ssh should be the user itself, not root or anyone else.

  • 1
    I'd set the file permissions but not the directory - changing this, it now works. – symcbean Aug 28 '15 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.