我试图从跳转服务器登录到路由器。我尝试了这段代码,但它给出了我无法理解的错误。请让我知道如何解决此错误或从跳转服务器登录路由器的任何其他方式。
试过的代码:
from dotenv import load_dotenv
import jumpssh
import os
from jumpssh import SSHSession
load_dotenv()
jumpserver_ip = os.getenv("jumpserver_ip")
jumpserver_username = os.getenv("jumpserver_username")
jumpserver_password = os.getenv("jumpserver_password")
remote_ip = os.getenv("remote_ip")
remote_password = os.getenv("remote_password")
gateway_session = SSHSession(jumpserver_ip, jumpserver_username, password=jumpserver_password).open()
remote_session = gateway_session.get_remote_session(remote_ip, password=remote_password, allow_agent=False, look_for_keys=False)
fl = open('R1.txt', 'w')
fl.write(remote_session.get_cmd_output('show running config'))
fl.close()
remote_session.close()
gateway_session.close()
错误:
Traceback (most recent call last):
File "C:\python3\JUMPSE~1\jump\DOTENV~1\lib\site-packages\jumpssh\session.py", line 160, in open
self.ssh_client.connect(**self.extra_parameters)
File "C:\python3\JUMPSE~1\jump\DOTENV~1\lib\site-packages\paramiko\client.py", line 446, in connect
passphrase,
File "C:\python3\JUMPSE~1\jump\DOTENV~1\lib\site-packages\paramiko\client.py", line 764, in _auth
raise saved_exception
File "C:\python3\JUMPSE~1\jump\DOTENV~1\lib\site-packages\paramiko\client.py", line 751, in _auth
self._transport.auth_password(username, password)
File "C:\python3\JUMPSE~1\jump\DOTENV~1\lib\site-packages\paramiko\transport.py", line 1509, in auth_password
return self.auth_handler.wait_for_response(my_event)
File "C:\python3\JUMPSE~1\jump\DOTENV~1\lib\site-packages\paramiko\auth_handler.py", line 250, in wait_for_response
raise e
paramiko.ssh_exception.AuthenticationException: Authentication failed.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "jump.py", line 17, in <module>
remote_session = gateway_session.get_remote_session(remote_ip, password=remote_password, allow_agent=False, look_for_keys=False)
File "C:\python3\JUMPSE~1\jump\DOTENV~1\lib\site-packages\jumpssh\session.py", line 514, in get_remote_session
retry_interval=retry_interval)
File "C:\python3\JUMPSE~1\jump\DOTENV~1\lib\site-packages\jumpssh\session.py", line 174, in open
% (self.host, self.port, self.username), original_exception=ex)
jumpssh.exception.ConnectionError: Unable to connect to '10.10.10.1:22' with user 'abc': Authentication failed.
我的 jump.env 文件:
jumpserver_ip = 'your_jump_server_ip'
jumpserver_username = 'your_jump_server_username'
jumpserver_password = 'your_jump_server_password'
remote_ip = 'your_remote_node_ip'
remote_username = 'your_remote_node_username'
remote_password = 'your_remote_node_password'
让我知道问题所在或任何其他登录方式。