无法在Mac OS El Capitan上使用ssh localhost

时间:2016-05-22 17:11:03

标签: rsa public-key sshd dsa

我在尝试创建ssh localhost连接时遇到了一些麻烦。我想在没有密码的情况下这样做,所以当我创建公钥/私钥对时,我会在被要求输入密码时输入返回密钥,如图所示。 当我尝试命令

    ssh localhost

我仍然被要求输入密码。所以我认为问题可能来自一些参数,避免使用没有密码的公钥,我创建了一个带密码的新的publickey / privatekey对。但是,我仍然收到以下消息:

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

有关信息,我使用以下命令创建了关键字:

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

完成一些研究后,我发现错误的权限会导致问题,所以这里是命令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

我还在详细模式下运行ssh(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 *
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: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: curve25519-sha256@libssh.org,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: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-ed25519,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,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: curve25519-sha256@libssh.org,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: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
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 chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <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).

有一个朋友和我一样拥有相同的笔记本电脑(最后一个mbp Retina 13“),ssh localhost工作得很好,我注意到他在执行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 *

为了记录,我已经检查了这些页面并尝试了所提议的内容,但没有成功: SSH: "Bad passphrase" after generation of public keyssh: Permission denied (publickey,keyboard-interactive) 提前感谢任何建议,想法或解决方案

4 个答案:

答案 0 :(得分:1)

您可以尝试使用特定的密钥进行授权:

ssh localhost -i ~/.ssh/id_dsa

如果成功,则可以将其添加到〜/ .ssh / config的ssh配置文件中。 如果不存在这样的文件,只需通过touch或vi进行创建。

配置应如下所示,请相应修改:

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

祝你好运!

答案 1 :(得分:0)

来自sshd(8)的手册页:

  

~/.ssh/authorized_keys

     

该文件的内容不是高度敏感的,但建议的权限是用户可读/写的,其他人无法访问。

您会在服务器日志中找到有关不使用authorized_keys的内容,因为它具有过多的权限。您应该仅将权限更改为可读写:chmod 600 ~/.ssh.authorized_keys

答案 2 :(得分:0)

我遇到了与dsa密钥相同的问题,所以改为尝试使用rsa密钥,它运行正常。要生成rsa密钥,只需将-t标志更改为&#39; -t rsa&#39;。

答案 3 :(得分:0)

我按照问题和上面的回答中提到的相同流程进行操作,只是无法让它接受无密码登录。

以下步骤为我解决了这个问题,我怀疑真正的敲弯器正在运行:
$ 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 tallamjr@Tareks-MacBook-Pro.local

20:07:58 ✔ /etc  :: ssh-add -l
2048 SHA256:-------------HASH------------- tallamjr@Tareks-MacBook-Pro.local (RSA)

20:08:18 ✔ /etc  :: ssh-keygen -l -f ~/.ssh/id_rsa.pub
2048 SHA256:-----------SAME-HASH---------- tallamjr@Tareks-MacBook-Pro.local (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:从here启发而来的步骤