亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python paramiko.ssh_exception.SSHException:沒有現有會話

Python paramiko.ssh_exception.SSHException:沒有現有會話

慕雪6442864 2023-07-27 16:43:11
host = "test.rebex.net"port = 22username = "demo"password = "password"command = "ls"ssh = paramiko.SSHClient()ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())ssh.connect(host, port, username, password)stdin, stdout, stderr = ssh.exec_command(command)lines = stdout.readlines()print(lines)應該產生這個輸出。['aspnet_client\n', 'pub\n', 'readme.txt\n']該憑證在該演示網站上運行良好wolf@linux:~$ sshpass -p password ssh [email protected] to Rebex Virtual Shell!For a list of supported commands, type 'help'.demo@ETNA:/$?demo@ETNA:/$ lsaspnet_clientpubreadme.txtdemo@ETNA:/$?但是,該代碼無法按預期工作。我在行后立即收到錯誤ssh.connect(host, port, username, password)。>>> import paramiko>>> host = "test.rebex.net">>> username = "demo">>> password = "password">>> port = 22>>>?>>> command = "ls">>>?>>> ssh = paramiko.SSHClient()>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())>>> ssh.connect(host, port, username, password)Traceback (most recent call last):? File "<stdin>", line 1, in <module>? File "/home/wolf/.local/lib/python3.8/site-packages/paramiko/client.py", line 435, in connect? ? self._auth(? File "/home/wolf/.local/lib/python3.8/site-packages/paramiko/client.py", line 764, in _auth? ? raise saved_exception? File "/home/wolf/.local/lib/python3.8/site-packages/paramiko/client.py", line 751, in _auth? ? self._transport.auth_password(username, password)? File "/home/wolf/.local/lib/python3.8/site-packages/paramiko/transport.py", line 1498, in auth_password? ? raise SSHException("No existing session")paramiko.ssh_exception.SSHException: No existing session>>>?讓我知道如何使其發揮作用。我只想要一個用于 SSH 連接的簡單代碼。更新>>> ssh.connect(host, port, username, password, look_for_keys=False, allow_agent=False)>>>?
查看完整描述

1 回答

?
紅顏莎娜

TA貢獻1842條經驗 獲得超13個贊

該代碼對我有用。


當我在 Pageant 中加載密鑰時,我也遇到錯誤auth_password(盡管不同 - “身份驗證失敗” )。在 Paramiko 嘗試使用 Pageant 密鑰后,Rebex 測試服務器似乎關閉了會話。連續密碼認證失敗。我想你的情況也會有類似的問題。不同的錯誤消息可能只是由于時間差異造成的。


starting thread (client mode): 0x33629f0

Local version/idstring: SSH-2.0-paramiko_2.6.0

Remote version/idstring: SSH-2.0-RebexSSH_5.0.7448.0

Connected (version 2.0, client RebexSSH_5.0.7448.0)

kex algos:['curve25519-sha256', '[email protected]', 'ecdh-sha2-nistp521', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp256', 'diffie-hellman-group16-sha512', 'diffie-hellman-group15-sha512', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group14-sha256', 'diffie-hellman-group14-sha1', 'diffie-hellman-group-exchange-sha1'] server key:['ssh-ed25519', 'ecdsa-sha2-nistp256', 'rsa-sha2-512', '[email protected]', 'rsa-sha2-256', 'ssh-rsa'] client encrypt:['[email protected]', '[email protected]', 'aes256-ctr', 'aes256-cbc', 'aes192-ctr', 'aes192-cbc', 'aes128-ctr', 'aes128-cbc', '[email protected]', 'twofish256-ctr', 'twofish192-ctr', 'twofish128-ctr', 'twofish256-cbc', 'twofish192-cbc', 'twofish128-cbc', 'twofish-cbc', '3des-ctr', '3des-cbc'] server encrypt:['[email protected]', '[email protected]', 'aes256-ctr', 'aes256-cbc', 'aes192-ctr', 'aes192-cbc', 'aes128-ctr', 'aes128-cbc', '[email protected]', 'twofish256-ctr', 'twofish192-ctr', 'twofish128-ctr', 'twofish256-cbc', 'twofish192-cbc', 'twofish128-cbc', 'twofish-cbc', '3des-ctr', '3des-cbc'] client mac:['[email protected]', '[email protected]', 'hmac-sha2-512', 'hmac-sha2-256', 'hmac-sha1', 'hmac-sha1-96'] server mac:['[email protected]', '[email protected]', 'hmac-sha2-512', 'hmac-sha2-256', 'hmac-sha1', 'hmac-sha1-96'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False

Kex agreed: [email protected]

HostKey agreed: ssh-ed25519

Cipher agreed: aes128-ctr

MAC agreed: hmac-sha2-256

Compression agreed: none

kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>

Switch to new keys ...

Adding ssh-ed25519 host key for test.rebex.net: b'e7e445c6b8e4bbd868892786fd0158f0'

Trying SSH agent key b'3f3ae3e3b0e0ef4e5b4bfe93613557d4'

userauth is OK

Authentication (publickey) failed.

Disconnect (code 2): Authentication is already in progress.

如果您想避免嘗試 Pageant,請使用allow_agent以下參數SSHClient.connect

ssh.connect(host,?port,?username,?password,?allow_agent=False)

強制性警告:請勿使用-這樣做您將失去針對MITM 攻擊的AutoAddPolicy保護。


查看完整回答
反對 回復 2023-07-27
  • 1 回答
  • 0 關注
  • 600 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號