我有一个经常登录的服务器。每次登录时我都必须输入密码。我正在尝试改变这种情况...
我严格按照教程操作。在服务器上,我使用 ssh-keygen 生成 id_rsa* 文件对。我将 .pub 添加到 authorized_keys,并检查 .ssh 目录和 authorized_keys 文件的权限。然后,我将 id 文件复制到我的家用电脑,确认所有权限,然后进行测试。没有用。我再次尝试在客户端生成密钥并将其推送到服务器。这也没有用。我又回到了在服务器上生成密钥,并试图找出问题所在……
我从客户端运行了“ssh -vvv”,以下是输出(已清理):
OpenSSH_5.9p1, OpenSSL 0.9.8x 10 May 2012
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to SERVER [IP-ADDRESS] port 22.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/Users/USER/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /Users/USER/.ssh/id_rsa type 1
debug1: identity file /Users/USER/.ssh/id_rsa-cert type -1
debug1: identity file /Users/USER/.ssh/id_dsa type -1
debug1: identity file /Users/USER/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "SERVER" from file "/Users/USER/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /Users/USER/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],ssh-rsa
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: 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],ssh-rsa,[email protected],[email protected],ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,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: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
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
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
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
debug2: dh_gen_key: priv key bits set: 131/256
debug2: bits set: 512/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
debug3: load_hostkeys: loading entries for host "SERVER" from file "/Users/USER/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /Users/USER/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug3: load_hostkeys: loading entries for host "IP-ADDRESS" from file "/Users/USER/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /Users/USER/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug1: Host 'SERVER' is known and matches the RSA host key.
debug1: Found key in /Users/USER/.ssh/known_hosts:1
debug2: bits set: 508/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
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: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /Users/USER/.ssh/id_rsa (0x7ffc1041d270)
debug2: key: /Users/USER/.ssh/id_dsa (0x0)
debug3: input_userauth_banner
...
debug1: Authentications that can continue: publickey,gssapi-with-mic,password,keyboard-interactive
debug3: start over, passed a different list publickey,gssapi-with-mic,password,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 RSA public key: /Users/USER/.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,keyboard-interactive
debug1: Trying private key: /Users/USER/.ssh/id_dsa
debug3: no such identity: /Users/USER/.ssh/id_dsa
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
我查看了服务器上的配置 (/etc/ssh/sshd_config),没有发现任何明显的原因导致它无法工作。我将其与另一台已成功设置的服务器上的配置进行了比较,唯一的区别是这台服务器有一行“RSAAuthentication yes”,而实际工作的服务器没有该行。
如果重要的话,服务器是
Linux SERVER 2.6.18-194.17.4.el5 #1 SMP Wed Oct 20 13:03:08 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
我的客户是一台 Mac:
Darwin CLIENT 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64
我实际上无法查看服务器上的 /var/log/secure 日志文件,因为我不是此机器的管理员。所以我感觉有点盲目和困惑。
对于如何进行有什么想法吗?
答案1
尝试使用 ssh-copy-id 将公钥复制到远程机器。
ssh-copy-id [-i [identity_file]] [user@]machine
我不知道 Mac 是否有这个工具,但它在我的 RHEL 机器上。这应该会从 authorized_keys 配置中删除用户配置错误。显然,只有在基本登录工作正常后才锁定 authorized_key 设置(来自、环境等)。
答案2
该过程是ssh-keygen
在客户端上运行,然后将(客户端上的)内容粘贴到服务器上的.ssh/id_rsa.pub
文件中。.ssh/authorized_keys
实际上,您为自己制作一个密钥,然后告诉服务器,您制作的密钥(由公共部分标识)被授权启动 SSH 会话。
答案3
您的 RSA 密钥在此处提供:
debug1: Offering RSA public key: /Users/USER/.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,keyboard-interactive
debug1: Trying private key: /Users/USER/.ssh/id_dsa
服务器的日志说了什么?/var/log/secure 还是 /var/log/auth。