Python ssh using Tor proxy

僤鯓⒐⒋嵵緔 提交于 2019-12-03 13:46:13

You need to create ProxyCommand (a socket-like object) and pass it to client.connect()

import paramiko

conf = paramiko.SSHConfig()
conf.parse(open('/home/user/.ssh/config'))
host = conf.lookup('host')
print host

proxy = paramiko.ProxyCommand(host['proxycommand'])

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host["hostname"], username=host["user"], password='test', sock=proxy)
client.close()

Docs for connect() method. Note timeout parameter. It's always a good idea to specify it if you are doing some automation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!