我现在很绝望.....我搜索了互联网,尝试了无数不同的解决方法、权限重置等,但到目前为止都没有任何帮助。
SSH 连接以前可以正常工作多年,但在 12 月 30 日却莫名其妙地停止工作。我尝试重新创建密钥,将它们复制到目标服务器,将它们添加到 AUTHORIZED_KEYS,但没有任何效果。我尝试按照许多网络建议设置权限,但无济于事。
我有 2 台服务器,都是 Solaris 10。
服务器 1(连接来源)
[~/.ssh] $ ls -altr
total 106
-rwxr-xr-x 1 informat informat 606 May 5 2016 id_dsa.pub.pfolio-ukbhu051p
-rwxr-xr-x 1 informat informat 627 May 5 2016 id_dsa.pub.eadmzu082p
-rwxr-xr-x 1 informat informat 606 May 5 2016 id_dsa.pub.51p-pfolio
-rwxr-xr-x 1 informat informat 1688 May 5 2016 authorized_keys
-rwxr-xr-x 1 informat informat 6449 Aug 24 2016 known_hosts_F0074033
-rwxr-xr-x 1 informat informat 7093 Apr 23 2017 known_hosts_20170423
-rwxr-xr-x 1 root root 5422 Mar 14 2018 known_hosts-140318
drwxr-xr-x 13 informat informat 1024 Nov 9 2019 ..
-rwxr-xr-x 1 informat informat 6452 Jan 6 13:45 known_hosts.adw.bak
-rwxr-xr-x 1 informat informat 1688 Jan 7 10:27 authorized_keys.20210107
-rw------- 1 informat informat 887 Jan 7 10:27 id_rsa.20210107
-rw-r--r-- 1 informat informat 229 Jan 7 10:27 id_rsa.pub.20210107
-rwxr-xr-x 1 informat informat 5954 Jan 7 10:27 known_hosts.20210107
-rw------- 1 informat informat 887 Jan 7 11:00 id_rsa
-rw-r--r-- 1 informat informat 229 Jan 7 11:01 id_rsa.pub
drwx------ 2 informat informat 1024 Jan 8 08:50 .
-rw-r--r-- 1 informat informat 229 Jan 8 08:50 identity
-rwxr-xr-x 1 informat informat 5954 Jan 8 09:09 known_hosts
服务器 2(连接目标)
-> ls -altr
total 194
-rw-r--r-- 1 pfolio cms 5975 Sep 15 2012 known_hosts.bck
-rw-r--r-- 1 pfolio cms 9880 Sep 15 2012 known_hosts_old
-rw-r----- 1 pfolio cms 226 Sep 15 2012 id_rsa.pub
-rw-r----- 1 pfolio cms 226 Sep 15 2012 id_rsa.020p
-rw------- 1 pfolio cms 887 Sep 15 2012 id_rsa
-rw-r----- 1 pfolio cms 606 Sep 15 2012 id_dsa.pub
-rw------- 1 pfolio cms 668 Sep 15 2012 id_dsa
-rw------- 1 pfolio cms 1167 Sep 15 2012 authorized_keys.old
-rw-r--r-- 1 pfolio cms 14750 Apr 17 2016 known_hosts_UKBHSFILES_CR
-rw-r----- 1 pfolio cms 229 May 25 2016 id_rsa.informat-eadmzu061p.pub
-rw-r--r-- 1 pfolio cms 16648 Apr 23 2017 known_hosts_20170423
-rw-r--r-- 1 pfolio cms 15836 Mar 19 2018 known_hosts.bak
-rw-r--r-- 1 pfolio cms 16241 Mar 19 2018 known_hosts
-rw------- 1 pfolio cms 458 Jan 6 13:40 authorized_keys.adw.bak
-rw-r----- 1 pfolio cms 229 Jan 6 13:41 id_rsa.pub.informat-eadmzu091p.bak
-rwx------ 1 pfolio cms 229 Jan 6 13:42 id_rsa.pub.informat-eadmzu091p
-rw-r--r-- 1 pfolio cms 229 Jan 7 10:35 id_rsa_new.pub.informat-eadmzu091p
-rw------- 1 pfolio cms 458 Jan 7 10:36 authorized_keys.20210107
-rw-r--r-- 1 pfolio cms 229 Jan 7 11:02 informat_eadmzu091p.pub
drwx------ 2 pfolio cms 1024 Jan 7 11:03 .
-rw------- 1 pfolio cms 458 Jan 7 11:03 authorized_keys
drwxrwxr-x 19 pfolio cms 1024 Jan 7 16:00 ..
连接尝试的调试.....它似乎发送了公钥,但未被接受。我检查了目标服务器上的日志,但没有看到任何有趣的东西。
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: check_host_in_hostfile: filename /export/informatica64/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 17
debug3: check_host_in_hostfile: filename /export/informatica64/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 16
debug1: Host 'ukbhc052p' is known and matches the RSA host key.
debug1: Found key in /export/informatica64/.ssh/known_hosts:17
debug1: bits set: 2080/4095
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug3: kex_reset_dispatch -- should we dispatch_set(KEXINIT) here? 0 && !0
debug2: set_newkeys: mode 1
debug1: set_newkeys: setting new keys for 'out' mode
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: set_newkeys: setting new keys for 'in' mode
debug1: SSH2_MSG_NEWKEYS received
debug1: done: ssh_kex2.
debug1: send SSH2_MSG_SERVICE_REQUEST
debug2: service_accept: ssh-userauth
debug1: got SSH2_MSG_SERVICE_ACCEPT
debug1: Authentications that can continue: gssapi-keyex,gssapi-with-mic,publickey,password,keyboard-interactive
debug3: start over, passed a different list gssapi-keyex,gssapi-with-mic,publickey,password,keyboard-interactive
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-keyex
debug3: remaining preferred: gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-keyex
debug1: Next authentication method: gssapi-keyex
debug2: we did not send a packet, disable method
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug1: Failed to acquire GSS-API credentials for any mechanisms (No credentials were supplied, or the credentials were unavailable or inaccessible
Unknown code 0
)
debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
**debug1: Next authentication method: publickey
debug1: Trying public key: /export/informatica64/.ssh/identity
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply**
debug1: Authentications that can continue: gssapi-keyex,gssapi-with-mic,publickey,password,keyboard-interactive
debug1: Trying public key: /export/informatica64/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: gssapi-keyex,gssapi-with-mic,publickey,password,keyboard-interactive
debug1: Trying private key: /export/informatica64/.ssh/id_dsa
debug3: no such identity: /export/informatica64/.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
Password:
目标服务器 SSHD_CONFIG
cat sshd_config
#
# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "@(#)sshd_config 1.8 04/05/10 SMI"
#
# Configuration file for sshd(1m)
# Protocol versions supported
#
# The sshd shipped in this release of Solaris has support for major versions
# 1 and 2. It is recommended due to security weaknesses in the v1 protocol
# that sites run only v2 if possible. Support for v1 is provided to help sites
# with existing ssh v1 clients/servers to transition.
# Support for v1 may not be available in a future release of Solaris.
#
# To enable support for v1 an RSA1 key must be created with ssh-keygen(1).
# RSA and DSA keys for protocol v2 are created by /etc/init.d/sshd if they
# do not already exist, RSA1 keys for protocol v1 are not automatically created.
# Uncomment ONLY ONE of the following Protocol statements.
# Only v2 (recommended)
Protocol 2
# Both v1 and v2 (not recommended)
#Protocol 2,1
# Only v1 (not recommended)
#Protocol 1
# Listen port (the IANA registered port number for ssh is 22)
Port 22
# The default listen address is all interfaces, this may need to be changed
# if you wish to restrict the interfaces sshd listens on for a multi homed host.
# Multiple ListenAddress entries are allowed.
# IPv4 only
#ListenAddress 0.0.0.0
# IPv4 & IPv6
ListenAddress ::
# Port forwarding
AllowTcpForwarding no
# If port forwarding is enabled, specify if the server can bind to INADDR_ANY.
# This allows the local port forwarding to work when connections are received
# from any remote host.
GatewayPorts no
# X11 tunneling options
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
# The maximum number of concurrent unauthenticated connections to sshd.
# start:rate:full see sshd(1) for more information.
#MaxStartups 10:30:100
# Banner to be printed before authentication starts.
#Banner /etc/issue
# Should sshd print the /etc/motd file and check for mail.
# On Solaris it is assumed that the login shell will do these (eg /etc/profile).
PrintMotd yes
# KeepAlive specifies whether keep alive messages are sent to the client.
# See sshd(1) for detailed description of what this means.
# Note that the client may also be sending keep alive messages to the server.
KeepAlive yes
# Syslog facility and level
SyslogFacility auth
LogLevel info
#
# Authentication configuration
#
# Host private key files
# Must be on a local disk and readable only by the root user (root:sys 600).
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
# Default Encryption algorithms and Message Authentication codes
#Ciphers aes128-ctr,aes128-cbc,arcfour,3des-cbc,blowfish-cbc
#MACS hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96
# Length of the server key
# Default 768, Minimum 512
ServerKeyBits 768
# sshd regenerates the key every KeyRegenerationInterval seconds.
# The key is never stored anywhere except the memory of sshd.
# The default is 1 hour (3600 seconds).
KeyRegenerationInterval 3600
# Ensure secure permissions on users .ssh directory.
#StrictModes yes
# Length of time in seconds before a client that hasn't completed
# authentication is disconnected.
# Default is 600 seconds. 0 means no time limit.
LoginGraceTime 600
# Maximum number of retries for authentication
# Default is 6. Default (if unset) for MaxAuthTriesLog is MaxAuthTries / 2
MaxAuthTriesLog 3
# Are logins to accounts with empty passwords allowed.
# If PermitEmptyPasswords is no, pass PAM_DISALLOW_NULL_AUTHTOK
# to pam_authenticate(3PAM).
PermitEmptyPasswords no
# To disable tunneled clear text passwords, change PasswordAuthentication to no.
PasswordAuthentication yes
# Use PAM via keyboard interactive method for authentication.
# Depending on the setup of pam.conf(4) this may allow tunneled clear text
# passwords even when PasswordAuthentication is set to no. This is dependent
# on what the individual modules request and is out of the control of sshd
# or the protocol.
PAMAuthenticationViaKBDInt yes
# Are root logins permitted using sshd.
# Note that sshd uses pam_authenticate(3PAM) so the root (or any other) user
# maybe denied access by a PAM module regardless of this setting.
# Valid options are yes, without-password, no.
PermitRootLogin yes
# sftp subsystem
Subsystem sftp internal-sftp
# SSH protocol v1 specific options
#
# The following options only apply to the v1 protocol and provide
# some form of backwards compatibility with the very weak security
# of /usr/bin/rsh. Their use is not recommended and the functionality
# will be removed when support for v1 protocol is removed.
# Should sshd use .rhosts and .shosts for password less authentication.
IgnoreRhosts yes
RhostsAuthentication no
# Rhosts RSA Authentication
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts.
# If the user on the client side is not root then this won't work on
# Solaris since /usr/bin/ssh is not installed setuid.
RhostsRSAAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication.
#IgnoreUserKnownHosts yes
# Is pure RSA authentication allowed.
# Default is yes
RSAAuthentication yes
#TFS specific Settings for USer access
AllowUsers root orca waltersg mon oracle dbaop2 burmane winsera kennedn qualys smithd doublem pfolio lipedee adminsc bowryc gibsonc mckennae harrisj waltersj kucukeksiv robinsona godfreyr robinsond wilsoni reillyj heardo futerss skerrittt bowryc gatesb nortjed egglesj detarantoa
MaxAuthTries 3
任何帮助都感激不尽
答案1
如果 SSH 连接尝试已开始提示您尝试连接的用户输入密码,请更改:
PasswordAuthentication yes
到
PasswordAuthentication no
在你的里面sshd_config
。
此外,它还试图在表面上可能不存在的位置找到你的私钥:
debug1: Trying private key: /export/informatica64/.ssh/id_dsa
debug3: no such identity: /export/informatica64/.ssh/id_dsa
我还看不到AuthorizedKeysFile
您sshd_config
指向您的authorized_keys文件所在位置的位置。
一个简单的建议:取消注释#StrictModes yes
以确保它对您的用户的 ~/.ssh 目录使用了正确的权限。
看:https://docs.oracle.com/cd/E86824_01/html/E54775/sshd-config-4.html
一旦您禁用PasswordAuthentication
并重新启动 ssh/sshd 服务,它可能会提示您出现不同的错误,您将能够具体地看到发生了什么,或者它应该修复它。
答案2
我们已设法通过执行以下操作来实现此功能......
我们恢复了 SSHD_CONFIG 文件的一个版本以确保它没有损坏,然后重新启动了 SSHD。这没有什么区别。
然后,我们尝试设置 StrictModes no,重新启动 SSH,然后在源服务器上提供更多提示。
由于某种原因,SSH 连接正在寻找名为 indentity 的文件,而不是原始的 rsa。我将 rsa 复制到identity,将 rsa.pub 复制到identity.pub。
现在运行连接时无需提示输入密码。
我不知道是什么原因导致了这些改变的必要性,但鉴于我们近期将更换这些服务器,我们不会去寻找根本原因。