Skip to content

Commit

Permalink
Merge pull request #1571 from minrk/paramiko-auto-add
Browse files Browse the repository at this point in the history
support configurable paramiko ssh policy
  • Loading branch information
minrk committed Aug 1, 2021
2 parents 537b169 + 9eb79a2 commit c7be48b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions zmq/ssh/tunnel.py
Expand Up @@ -122,8 +122,16 @@ def _try_passwordless_paramiko(server, keyfile):
raise ImportError(msg)
username, server, port = _split_server(server)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
known_hosts = os.path.expanduser("~/.ssh/known_hosts")
try:
client.load_host_keys(known_hosts)
except FileNotFoundError:
pass

policy_name = os.environ.get("PYZMQ_PARAMIKO_HOST_KEY_POLICY", None)
if policy_name:
policy = getattr(paramiko, f"{policy_name}Policy")
client.set_missing_host_key_policy(policy())
try:
client.connect(
server, port, username=username, key_filename=keyfile, look_for_keys=True
Expand Down

0 comments on commit c7be48b

Please sign in to comment.