如何设置 SSH 以便我不必输入密码并且不使用公钥?

Dav*_*d Z 9 ssh unix

我知道这里有很多关于如何在不每次输入密码的情况下连接到 SSH 服务器的问题,答案总是“使用公钥”。好吧,我发现自己处于一种罕见的情况,这真的不是一种选择。由于某些莫名其妙的原因,我尝试连接的服务器上的 OpenSSH 守护进程配置为

RSAAuthentication no
PubkeyAuthentication no
Run Code Online (Sandbox Code Playgroud)

/etc/ssh/sshd_config。我在服务器上没有任何管理访问权限,因此我无法更改这些或任何其他服务器配置选项。(当然,我可以完全控制客户端配置:Linux 上的 OpenSSH 5.8。)

我的选择是什么,特别是最安全的选择是什么,以避免每次我想通过 SSH 连接到此服务器时都必须输入密码?我将自己的计算机保护得相当好,所以让我们假设将密码存储在客户端上的文件中的安全风险是可以接受的,如果确实有必要的话。

服务器可以接受的其他身份验证方法显然是 GSS API(我一无所知)、键盘交互(我也一无所知)和密码。以下是一些相关的配置选项:

#ChallengeResponseAuthentication yes

#KerberosAuthentication no

GSSAPIAuthentication yes
GSSAPICleanupCredentials yes

#UsePAM no
Run Code Online (Sandbox Code Playgroud)

这是调试 ( -vv) 跟踪:

debug1: Authentications that can continue: gssapi-with-mic,password,keyboard-interactive
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_1000' not found
debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_1000' not found
debug1: Unspecified GSS failure.  Minor code may provide more information

debug1: Unspecified GSS failure.  Minor code may provide more information

debug2: we did not send a packet, disable method
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug1: Authentications that can continue: gssapi-with-mic,password,keyboard-interactive
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
Run Code Online (Sandbox Code Playgroud)

use*_*686 8

从目前收集的信息来看,该服务器sftp.pass.psu.edu支持 Kerberos 5 (GSSAPI) 身份验证并且在dce.psu.edu领域内。

Kerberos在具有许多服务器和工作站的网络中非常常见;许多大型教育机构都设立了它。与公钥身份验证相比,它的优势之一是单个kinit自动向 Kerberos 领域中的所有机器提供凭据,而无需将公钥复制到每台机器。另一个是协议支持——相同的 Kerberos 凭证可用于 30 多种协议(邮件、文件系统、数据库……),而不仅仅是 SSH。

(关于“无知的仅 Windows 管理员”:该dce.psu.edu领域实际上似乎基于 Active Directory,并由 Windows 服务器托管。)

尝试执行以下步骤:

  1. 登录到 Kerberos。(如果系统中尚未包含kinitklist工具,则可能位于“krb5-user”或类似包中。)

    kinit your_username @dce.psu.edu
    

    如果没有显示错误,则登录成功。klist应该显示一个“ krbtgt/dce.psu.edu@...”项目。

  2. 现在使用-vv选项连接到 SSH 服务器;如果认证成功,很好。

    如果没有,您可能需要编辑您的/etc/krb5.conf文件。在该[domain_realm]部分下,添加以下内容:

    [domain_realm]
        .psu.edu = dce.psu.edu
    
    Run Code Online (Sandbox Code Playgroud)
  3. 使用默认的 Krb5 设置,#1 中获得的票应在 10 小时内有效,最多可续订一周。但是,我无法验证设置。

    如果您想将密码保存在一个文件中,一个简单的kinit your_principal < password.txt应该可以工作,尽管它并不完全可靠。

    有了ktutil它,可以使一个“密钥表”的使用,而不是密码。

    $ ktutil
    ktutil: addent -password -p your_principal -k 1 -e aes256-cts-hmac-sha1-96your_principal 的
    密码:*********
    ktutil: wkt keytab_file 
    ktutil:  CtrlD
    

    并使用登录:

    $ kinit -kt keytab_file  your_principal
    


joh*_*n64 3

在这种情况下,编写(或更好地记录)期望脚本将是您的选择之一。

每个系统都不同,因此不会有脚本,但使用 autoexpect 可以很容易地为此目的录制脚本。