pip install paramiko import paramiko jssh = paramiko.SSHClient() jssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) jssh.connect('192.168.1.188', '22', 'root', 'cdp12345') #ssh连接 jssh = paramiko.SSHClient() jssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) key = paramiko.RSAKey.from_private_key_file('/tmp/id_rsa') jssh.connect('192.168.1.245', '22', 'root', pkey=key) #执行命令 stdin, stdout, stderr = jssh.exec_command('ls /tmp') stdout.read()