Python 对paramiko使用不同的密码
如何指定要在paramiko ssh/sftp连接上使用的不同密码?(类似于scp/ssh中的-c命令行) 我尝试了以下代码:Python 对paramiko使用不同的密码,python,paramiko,Python,Paramiko,如何指定要在paramiko ssh/sftp连接上使用的不同密码?(类似于scp/ssh中的-c命令行) 我尝试了以下代码: self.sshclient = paramiko.SSHClient() self.sshclient.load_system_host_keys() self.sshclient.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.sshclient.connect(h
self.sshclient = paramiko.SSHClient()
self.sshclient.load_system_host_keys()
self.sshclient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.sshclient.connect(hostname, **ssh_kwargs)
self.transport = self.sshclient.get_transport()
self.transport.get_security_options().ciphers = ('arcfour128',)
self.transport.set_keepalive(keepalive)
self.channel = self.transport.open_session()
self.channel.settimeout(timeout)
但在调试时,我可以看到:
2016/02/26 15:27:47 DEBUG Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
2016/02/26 15:27:47 DEBUG using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
我在某个地方读到,连接应该发生在
get\u security\u options()
更改这些字段的内容和/或顺序会影响基础传输(但仅当您在启动会话之前更改这些字段时)
您可以做的是覆盖传输
的首选密码:
paramiko.Transport._preferred_ciphers = ('arcfour128', )
self.sshclient = paramiko.SSHClient()
self.sshclient.load_system_host_keys()
self.sshclient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.sshclient.connect(hostname, **ssh_kwargs)
...
如果您只需要一个SFTP连接,您可以先创建一个传输
,然后从该传输创建SFTPClient
对象:
self.transport = paramiko.Transport((hostname, 22))
self.transport.get_security_options().ciphers = ('arcfour128', )
self.transport.connect(username=user, password=pass) # or pkeys, ...
self.transport.set_keepalive(keepalive)
self.sftp = paramiko.SFTPClient.from_transport(self.transport)
self.sftp.put('local_file', 'remote_path')
self.sftp.close()