S.Mcgalway
S.Mcgalway

Reputation: 11

Unable to ssh localhost on Mac OS El Capitan

I am having some troubles while trying to make a ssh localhost connexion. I want to do this without passphrase, so when I created the public key/private key couple, I typed on the return key when asked for the passphrase, as indicated. When I try the command

    ssh localhost

I still get asked for a password. So I thought that the problem could come from some parameter avoiding public keys without passphrase and I created a new publickey/privatekey couple with a passphrase. But still, I get the following message :

    Failing ssh to localhost : Permission denied (publickey,keyboard-interactive).

For information, I created the key couple with the command :

    ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

After having done some researches, I've read that wrong permissions can cause problems, so here is the result of the command ls -lha ~/.ssh/ :

    drwx------   7 matthieu  staff  238B 22 mai 17:50 .
    drwxr-xr-x+ 35 matthieu  staff  1,2K 22 mai 17:52 ..
    -rw-r--r--   1 matthieu  staff  612B 22 mai 17:50 authorized_keys
    -rw-------   1 matthieu  staff  672B 22 mai 17:49 id_dsa
    -rw-r--r--   1 matthieu  staff  612B 22 mai 17:49 id_dsa.pub
    -rw-r--r--   1 matthieu  staff  171B 22 mai 10:00 known_hosts

I also ran ssh in verbose mode (ssh -vvv localhost) which gives :

OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_rsa-cert type -1
debug1: identity file /Users/matthieu/.ssh/id_dsa type 2
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/matthieu/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.9
debug1: match: OpenSSH_6.9 pat OpenSSH* compat 0x04000000
debug2: fd 5 setting O_NONBLOCK
debug1: Authenticating to localhost:22 as 'matthieu'
debug3: hostkeys_foreach: reading file "/Users/matthieu/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/matthieu/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from localhost
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1,[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1,[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
debug2: kex_parse_kexinit: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: kex_parse_kexinit: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:A9YQlWJMyCIXIan+dT/wB4qYxQaJP7Z+fovz+88JDEg
debug3: hostkeys_foreach: reading file "/Users/matthieu/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /Users/matthieu/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from localhost
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /Users/matthieu/.ssh/known_hosts:1
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /Users/matthieu/.ssh/id_dsa (0x7fd3f0d13f70),
debug2: key: /Users/matthieu/.ssh/id_rsa (0x0),
debug2: key: /Users/matthieu/.ssh/id_ecdsa (0x0),
debug2: key: /Users/matthieu/.ssh/id_ed25519 (0x0),
debug1: Authentications that can continue: publickey,keyboard-interactive
debug3: start over, passed a different list publickey,keyboard-interactive
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering DSA public key: /Users/matthieu/.ssh/id_dsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Trying private key: /Users/matthieu/.ssh/id_rsa
debug3: no such identity: /Users/matthieu/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /Users/matthieu/.ssh/id_ecdsa
debug3: no such identity: /Users/matthieu/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /Users/matthieu/.ssh/id_ed25519
debug3: no such identity: /Users/matthieu/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup keyboard-interactive
debug3: remaining preferred: password
debug3: authmethod_is_enabled keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug2: input_userauth_info_req
debug2: input_userauth_info_req: num_prompts 1
Password:
debug1: Authentications that can continue: publickey,keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug2: input_userauth_info_req
debug2: input_userauth_info_req: num_prompts 1
Password:
debug1: Authentications that can continue: publickey,keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug2: input_userauth_info_req
debug2: input_userauth_info_req: num_prompts 1
Password:
debug1: Authentications that can continue: publickey,keyboard-interactive
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey,keyboard-interactive).

Having a friend who has got the same laptop as me (last mbp Retina 13"), with whom ssh localhost works fine, I noted that he's got the additional lines at the beginning when executing ssh -vvv localhost :

    OpenSSH_6.9p1, LibreSSL 2.1.8
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: /etc/ssh/ssh_config line 21: Applying options for *
    debug1: /etc/ssh/ssh_config line 56: Applying options for *

For the record, I already checked these pages and tried what's proposed, without success : SSH: "Bad passphrase" after generation of public key and ssh: Permission denied (publickey,keyboard-interactive) Thanks in advance for any advice, idea or solution

Upvotes: 1

Views: 2949

Answers (4)

tallamjr
tallamjr

Reputation: 1470

I followed the same flow as mentioned in the question as well as in the responses above and simply could not get it to accept a password-less login.

The following steps solved this for me and I suspect the real clincher was running:
$ eval `ssh-agent`

20:05:43 ✔ /etc  :: ssh localhost
Password:

20:05:51 ✘ /etc  :: eval `ssh-agent`
Agent pid 38262

20:07:44 ✔ /etc  :: ssh-add ~/.ssh/id_rsa
Identity added: /Users/tallamjr/.ssh/id_rsa [email protected]

20:07:58 ✔ /etc  :: ssh-add -l
2048 SHA256:-------------HASH------------- [email protected] (RSA)

20:08:18 ✔ /etc  :: ssh-keygen -l -f ~/.ssh/id_rsa.pub
2048 SHA256:-----------SAME-HASH---------- [email protected] (RSA)

20:08:29 ✔ /etc  :: ssh-copy-id -i ~/.ssh/id_rsa.pub tallamjr@localhost
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/tallamjr/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'tallamjr@localhost'"
and check to make sure that only the key(s) you wanted were added.

20:09:39 ✔ /etc  :: ssh tallamjr@localhost
Last login: Thu Jan 23 20:05:37 2020 from ::1

20:09:57 ✔ ~  :: exit
logout
Connection to localhost closed.

20:09:59 ✔ /etc  :: ssh localhost
Last login: Thu Jan 23 20:09:52 2020 from ::1

REF: Steps from inspired from here

Upvotes: 0

Ben
Ben

Reputation: 21

You may try to use specific key for authorization:

ssh localhost -i ~/.ssh/id_dsa

If succeed, then you can add it to ssh config file at ~/.ssh/config. If such a file is not existed, just create on via touch or vi.

The config should be something like below, please revise it accordingly:

Host localhost
    HostName 127.0.0.1
    Port 22
    user matthieu
    IdentityFile  ~/.ssh/id_dsa

Good luck!

Upvotes: 2

Chris Stone
Chris Stone

Reputation: 11

I had the same problem with a dsa key so instead tried an rsa key and it worked fine. To generate the rsa key, just change the -t flag to '-t rsa'.

Upvotes: 0

Jakuje
Jakuje

Reputation: 25986

From manual page for sshd(8):

~/.ssh/authorized_keys

The content of the file is not highly sensitive, but the recommended permissions are read/write for the user, and not accessible by others.

You will find in the server log something about not using your authorized_keys, because it has too wide permissions. You should change the permissions to be readable and writable only by you: chmod 600 ~/.ssh.authorized_keys

Upvotes: 0

Related Questions