使用PuTTY命令行,我与位于PAM上下文下的unix主机连接。
连接字符串是
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这将向主机和登录打开PuTTY SSH会话。在PuTTY控制台中,它将用户名显示为domain/user-name@pam-functional-account@unix-host
我想通过SSH图书馆Paramiko来做同样的事情。我保留了pam-load-balancer-address作为我的主机,4422作为端口,domain/user-name@pam-functional-account@unix-host作为我的用户名。在Paramiko中,它给出了一个错误消息。
AuthenticationException:身份验证失败。
在PuTTY ssh中,它是成功的,而在Paramiko或robotframework-sshlibrary中,我无法登录主机。请提供如何登录用户名有多个@的主机的建议。谢谢

PuTTY会话

PuTTY事件日志:

Paramiko日志:
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

没有PuTTY的-pw事件日志
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()发布于 2021-03-30 14:14:57
您的服务器似乎发出了两个键盘交互身份验证挑战。
password
所以你必须做这样的事情:
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)一些参考资料:
此外,正如您已经发现的,您需要在用户名中转义\。
https://stackoverflow.com/questions/66864569
复制相似问题