从使用PARAMIKO的服务器上尝试SSH并出现错误
import paramiko
class SSH_Connection(object):
def __init__(self, instance, mode,LOCAL_IP, username, password):
self.instance = instance
self.mode = mode
self.LOCAL_IP = LOCAL_IP
self.username = username
self.password = password
self.mode = mode
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.client.connect(self.LOCAL_IP, username=self.username, password=self.password)
def std(self,message):
self.message=message
_in, out, err = self.client.exec_command(self.message)
exitcode = out.channel.recv_exit_status()
stdout = ''.join(out.read())
stderr = ''.join(err.read())
return stdout,stderr, exitcode
class UNIT(SSH_Connection):
pass
unit = UNIT(1, 'live', 'x.x.x.x', username='root', password='something')
然后我尝试从“单元” SSH到另一台服务器:
unit.std('sshpass -p 123 ssh root@172.16.46.134 -y')
我得到以下信息:
"\nHost '172.16.46.134' key accepted unconditionally.\n(ecdsa-sha2-nistp256 fingerprint md5 e3:e7:05:73:ac:71:66:74:94:f3:31:2c:77:94:f3:5c)\nssh: Failed reading termmodes\n\nssh: Connection to root@172.16.46.134:22 exited: Failed to set raw TTY mode\n",
当我在Linux的“单元”中执行相同的操作时,此方法有效:
sshpass -p 123 ssh root@172.16.46.134 -y
我该怎么办才能使用paramiko从Python强制SSH,然后使用exe_command进行SSH?