Search code examples
macossshssh-keys

ssh Authentication failed on Mac


I tried to ssh a remote linux server with username and password on my Mac. But it shows the following mistake. It seems that it tries to login with rsa keys. But I want to login with password. (I can successfully login with password in Xshell in windows)

SSH command:

ssh -v -p 10022 qhdxliy@42.123.106.11

Debugging output:

OpenSSH_7.5p1, LibreSSL 2.5.4
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 52: Applying options for *
debug1: Connecting to 42.123.106.11 [42.123.106.11] port 10022.
debug1: Connection established.
debug1: identity file /Users/zhaokai/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/zhaokai/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/zhaokai/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/zhaokai/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/zhaokai/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/zhaokai/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/zhaokai/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/zhaokai/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5
debug1: Remote protocol version 2.0, remote software version     OpenSSH_100.0
debug1: match: OpenSSH_100.0 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 42.123.106.11:10022 as 'qhdxliy'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: diffie-hellman-group-exchange-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: umac-64@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-64@openssh.com compression: none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<3072<8192) sent
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ssh-rsa SHA256:iqMu6xmkaocbmHW4ejr0REqMGiIBVgaBz4CkocSwopI
debug1: Host '[42.123.106.11]:10022' is known and matches the RSA host key.
debug1: Found key in /Users/zhaokai/.ssh/known_hosts:7
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/zhaokai/.ssh/id_rsa
Authentication failed.

Solution

  • The password auth is tried after the public key. If you don't want your ssh client to try your public key first, use the PreferredAuthentications option, i.e.

    ssh -o "PreferredAuthentications=password" [other options... ]
    

    Source: the AUTHENTICATION section of ssh's manual page states:

    The methods available for authentication are: GSSAPI-based authentication, host-based authentication, public key authentication, challenge-response authentication, and password authentication. Authentication methods are tried in the order specified above, though PreferredAuthentications can be used to change the default order.