当前位置: 首页 > 知识库问答 >
问题:

使用Python Paramiko连接到SSH服务器,除了密码提示外,还需要提交带有Enter键的键盘交互横幅

冀阳文
2023-03-14

使用PuTTY命令行,我连接到unix主机,它是在PAM上下文下。

连接字符串

domain/user-name@pam-functional-account@unix-host@pam-load-balancer-address:4422

在PuTTY命令行中,我使用了以下命令

putty.exe -ssh domain/user-name@pam-functional-account@unix-host@pam-load-balancer-address 4422 -pw xxx

AuthenticationException:身份验证失败。

在PuTTY ssh中,它是成功的,而在Paramiko或robotframework-sshlibrary中,我无法登录主机。请提供关于如何登录用户名有许多@的主机的建议。谢谢

腻子会话

DEB [20210330-17:27:49.113] thr=1   paramiko.transport: starting thread (client mode): 0x3d82d30
DEB [20210330-17:27:49.113] thr=1   paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.7.2
DEB [20210330-17:27:49.113] thr=1   paramiko.transport: Remote version/idstring: SSH-2.0-PBPS-SM-1.0.0
INF [20210330-17:27:49.113] thr=1   paramiko.transport: Connected (version 2.0, client PBPS-SM-1.0.0)
DEB [20210330-17:27:49.217] thr=1   paramiko.transport: kex algos:['curve25519-sha256', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group14-sha1'] server key:['ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', 'ecdsa-sha2-nistp521', 'ssh-ed25519', 'rsa-sha2-512', 'rsa-sha2-256', 'ssh-rsa'] client encrypt:['aes256-ctr', 'aes192-ctr', 'aes128-ctr'] server encrypt:['aes256-ctr', 'aes192-ctr', 'aes128-ctr'] client mac:['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] server mac:['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEB [20210330-17:27:49.218] thr=1   paramiko.transport: Kex agreed: ecdh-sha2-nistp256
DEB [20210330-17:27:49.218] thr=1   paramiko.transport: HostKey agreed: ssh-ed25519
DEB [20210330-17:27:49.218] thr=1   paramiko.transport: Cipher agreed: aes128-ctr
DEB [20210330-17:27:49.218] thr=1   paramiko.transport: MAC agreed: hmac-sha2-256
DEB [20210330-17:27:49.218] thr=1   paramiko.transport: Compression agreed: none
DEB [20210330-17:27:49.225] thr=1   paramiko.transport: kex engine KexNistp256 specified hash_algo <built-in function openssl_sha256>
DEB [20210330-17:27:49.225] thr=1   paramiko.transport: Switch to new keys ...
DEB [20210330-17:27:49.226] thr=2   paramiko.transport: Adding ssh-ed25519 host key for [xxx-pam2.xxx.co.uk]:4422: b'3f537ba214609f1911ba04226de23df7'
DEB [20210330-17:27:49.246] thr=1   paramiko.transport: userauth is OK
INF [20210330-17:27:49.246] thr=1   paramiko.transport: Authentication (password) failed.
DEB [20210330-17:27:49.253] thr=1   paramiko.transport: EOF in transport thread

不带-pw的PuTTY事件日志:

2021-03-30 17:39:43 Looking up host "xxx-pam1.xxx.co.uk" for SSH connection
2021-03-30 17:39:43 Connecting to 10.34.37.244 port 4422
2021-03-30 17:39:43 We claim version: SSH-2.0-PuTTY_Release_0.74
2021-03-30 17:39:43 Remote version: SSH-2.0-PBPS-SM-1.0.0
2021-03-30 17:39:43 Using SSH protocol version 2
2021-03-30 17:39:43 No GSSAPI security context available
2021-03-30 17:39:43 Doing ECDH key exchange with curve nistp256 and hash SHA-256 (unaccelerated)
2021-03-30 17:39:43 Server also has ecdsa-sha2-nistp256/ecdsa-sha2-nistp384/ecdsa-sha2-nistp521/ssh-rsa host keys, but we don't know any of them
2021-03-30 17:39:43 Host key fingerprint is:
2021-03-30 17:39:43 ssh-ed25519 255 32:2f:d2:0b:ba:f4:50:7f:01:42:59:bd:47:17:d3:91
2021-03-30 17:39:43 Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
2021-03-30 17:39:43 Initialised HMAC-SHA-256 (unaccelerated) outbound MAC algorithm
2021-03-30 17:39:43 Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
2021-03-30 17:39:43 Initialised HMAC-SHA-256 (unaccelerated) inbound MAC algorithm
2021-03-30 17:39:43 Attempting keyboard-interactive authentication
2021-03-30 17:40:01 Access granted
2021-03-30 17:40:01 Opening main session channel
2021-03-30 17:40:02 Opened main channel
2021-03-30 17:40:02 Allocated pty
2021-03-30 17:40:02 Started a shell/command

源代码

import paramiko
import logging
import Interactive

def connect_pam_host():
    logging.basicConfig();
    # logging.getLogger('Paramiko').setLevel(logging.INFO);
    paramiko.util.log_to_file('paramiko.log', logging.WARNING);
    ssh = paramiko.SSHClient();
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy());
    ssh.connect(hostname='xxx-pam2.xxx.co.uk', port=4422, username='netdom\\tpukrisi@XXuladm@utvweccn03',
                password='mypwd@03');
    print('Success');


# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')
    connect_pam_host()

共有1个答案

施德运
2023-03-14

您的服务器似乎发出了两个键盘交互身份验证挑战

  • 首先,提示输入密码
  • 第二,没有提示的横幅。

所以你必须做这样的事情:

def handler(title, instructions, fields):
    if len(fields) == 1:
        return [password]
    else:
        return []

transport = paramiko.Transport('example.com') 
transport.connect(username='myuser')
transport.auth_password(username, password):
transport.auth_interactive(username, handler)
    null
 类似资料:
  • 本文向大家介绍js实现键盘Enter键提交表单的方法,包括了js实现键盘Enter键提交表单的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了js实现键盘Enter键提交表单的方法。分享给大家供大家参考。具体实现方法如下: 最后只需要在body中加入:<body onkeydown="keyDown(event);">。   或者如下方法,但是在火狐浏览器下不兼容: 希望本文所述对大家

  • 问题内容: 好吧,我试图通过按Enter提交表单,但不显示提交按钮。我不希望尽可能地使用JavaScript,因为我希望所有功能都可以在所有浏览器上正常工作(我知道的唯一JS方式就是使用事件)。 现在,表单如下所示: 哪个效果很好。当用户按下Enter键时,提交按钮将起作用,并且该按钮在Firefox,IE,Safari,Opera和Chrome中不显示。但是,我仍然不喜欢该解决方案,因为很难知道

  • 问题内容: 我只是写了这个漂亮的小函数,它可以在表单本身上工作… 按照我的逻辑,我想在输入textarea期间接受回车。同样,将输入字段的回车键行为替换为跳到下一个输入字段的行为(就像按下Tab键一样)将是额外的好处。有谁知道使用事件传播模型正确触发适当元素上的回车键,但阻止表单在其按下时提交的方法吗? 问题答案: 这是我功能的修改版本。它执行以下操作: 防止Enter键在除textarea,bu

  • 在这种特殊情况下,当我按Enter键时,我必须使用哪些选项使这些输入调用函数? Html:

  • 问题内容: PrimeFaces在按Enter键时禁用提交。 我正在运行在WildFly 8.2 Final上运行的PrimeFaces 5.1。 我有对话框,有两个inputNumbers和两个按钮。并且第一个inputNumber对ajax模糊事件进行一些计算。按钮旁边是在bean中进行一些计算的按钮。问题是,当用户在焦点位于inputNumber时按Enter时,按钮的动作被触发,这确实很烦

  • 我试图在Hyperledger fabric测试网络(Fabcar javascript智能合约)上执行智能合约,当我试图使用invoke调用链码时,会出现以下错误。fabcar javascript示例中的js文件: 错误:[ServiceEndpoint]:错误:未能在截止日期之前连接到委员会-名称:_buildOrderer,url:_buildPeer,连接:false,连接尝试:true