Directly in the code SSH The protocol performs operations on the remote server, Not through ssh Command to operate the remote server. With Paramiko in the future, We can do that Python Use. Ssh It's an agreement ,OpenSSH Is one of the open source implementations ,paramiko yes Python A library, Realized SSHv2 agreement ( Bottom use cryptography). Print(stdout.read().decode('utf-8')) # With utf-8 Encode and decode the result Stdin, stdout, stderr = ssh.exec_command(cmd) # Carry out orders, And get the results Ssh.connect(ip, port, username, passwd, timeout=5) # Connect to server, among timeout Is the timeout Ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # Allow connections know_hosts Host that does not exist in Ssh = paramiko.SSHClient() # Create a ssh object Say again paramiko Use : def test1(ip, port, username, passwd, cmd):
In this ssh.connect(.) Join in allow_agent=False,look_for_keys=False, as follows ssh.connect(ip, port, username, passwd, timeout=5,allow_agent=False,look_for_keys=False)
Jenkins docker ip timeout install#
Pip install paramiko # Re install it, Problem solving pip uninstall paramiko # Uninstall the original installation first Īfter careful study, Decide to uninstall the current version paramiko2.7.1, And then reinstall it, Found a new version paramiko2.7.2, It really solved the problem. Searched for a long time, I can't find the answer. ValueError: ('Invalid private key', ) terms of settlement 1: When the other host you connect to has SSH The secret key, When connecting with user name and password : When connecting with user name and password, an exception is encountered as follows : paramiko The library has two ways to connect to the host , In the process of software testing, Involving remote Linux When testing the host environment, It is inevitable to encounter the need to implement shell The scene of the command, Such as through shell Command to configure some environments or check the results of use case execution, etc, Then it is the use of more commonly used tools paramiko.