通过减少一次登录密码,可以使后续登录提示密码

通过减少一次登录密码,可以使后续登录提示密码

我需要在一台只能通过一些跳跃才能到达的机器上运行一个脚本。所以我写了一个小脚本:

ssh -t user1@host1 ssh -t user2@host2 ssh -t user3@host3 sript_to_run.sh

这很有效,并提示输入 host1、host2 的密码,但不输入 host3 的密码。

为了方便起见,我将我的公共信息rsa-key从我的计算机复制到 host1 以实现无密码登录。现在只提示我登录 host2,但其他都很好。

所以我对 host1 和 host2 做了同样的事情。现在我可以登录到 host2 而无需任何密码提示。但我现在需要在 host3 上使用密码登录...不幸的是,我不知道 host3 上的无密码登录是如何工作的,而且我不允许附加文件authorized_keys

因此,我假设 host3 以某种方式知道我如何登录 host2。我能以某种方式欺骗 host3,让其认为 host2 是通过密码提示登录的吗?或者还有其他方法可以无密码运行脚本?

以下是最后 ssh 步骤的详细输出(#为保持匿名,所有内容均被删除):

OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to mcc-console [#IP#] port 22.
debug1: Connection established.
debug1: identity file /reg/neh/home/#USER#/.ssh/identity type -1
debug1: identity file /reg/neh/home/#USER#/.ssh/id_rsa type -1
debug1: identity file /reg/neh/home/#USER#/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
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
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '#HOST3#' is known and matches the RSA host key.
debug1: Found key in /reg/neh/home/#USER#/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Next authentication method: publickey
debug1: Trying private key: /reg/neh/home/#USER#/.ssh/identity
debug1: read PEM private key done: type DSA
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /reg/neh/home/#USER#/.ssh/id_rsa
debug1: Trying private key: /reg/neh/home/#USER#/.ssh/id_dsa
debug1: Next authentication method: password

答案1

几点评论,不确定是否能回答你所有的疑问:

  1. 将您的私钥复制到远程机器是错误的,如果它们不是完全受信任的(物理访问,只有您才能进行 root 访问)。如果您确实需要从远程机器使用密钥,则有一个名为 的功能AgentForwarding,它可以以更好的方式完成此操作(谷歌阅读更多内容)

  2. 设置跳转主机也是一个众所周知的问题。是的,你可以按照现在的方式去做,但你会犯我上面提到的错误。为什么要这样做呢,当有更好的方法,叫做ProxyCommand?这样,你可以把所有的私钥操作留在你信任的机器上,这是可取的(谷歌,很多次在超级用户或维基百科)。

对于您的问题:

我是否可以以某种方式欺骗 host3,让其认为 host2 已通过密码提示登录?

不确定你这是什么意思。

或者是否有其他无需密码即可运行脚本的方法?

除了密码之外,还有很多方法可以向服务器进行身份验证。有使用 GSSAPI 的 Kerberos,有基于主机的身份验证,但所有这些都需要事先进行一些设置。如果您无法控制host3并且被禁止设置公钥,那么您确实需要使用密码。但如果没有更多信息,我帮不上忙。服务器日志中的故障也有助于调查问题。

相关内容