From 29148552f2110d7b3739f48e11b162c9c17f5246 Mon Sep 17 00:00:00 2001 From: Meni Yakove <441263+myakove@users.noreply.github.com> Date: Fri, 20 Mar 2020 11:50:35 +0200 Subject: [PATCH] Enable to set ssh key from os enviroment (#126) --- README.rst | 5 +++++ rrmngmnt/ssh.py | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index de3ecbb..f1dafa1 100644 --- a/README.rst +++ b/README.rst @@ -20,9 +20,14 @@ that means SSH server must be running there already. h = Host("10.11.12.13") h.users.append(RootUser('123456')) + + # Use with ssh key. export HOST_SSH_KEY to use specific ssh key, default is ~/.ssh/id_rsa + host.executor_factory = rrmngmnt.ssh.RemoteExecutorFactory(use_pkey=True) + exec = h.executor() print exec.run_cmd(['echo', 'Hello World']) + Features -------- diff --git a/rrmngmnt/ssh.py b/rrmngmnt/ssh.py index e860594..cf4329c 100644 --- a/rrmngmnt/ssh.py +++ b/rrmngmnt/ssh.py @@ -61,7 +61,9 @@ def __init__(self, executor, timeout=None): self._ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) if self._executor.use_pkey: self.pkey = paramiko.RSAKey.from_private_key_file( - ID_RSA_PRV % os.path.expanduser('~') + os.getenv( + "HOST_SSH_KEY", ID_RSA_PRV % os.path.expanduser('~') + ) ) self._executor.user.password = None else: