From ce117280a9b947e7631393d6130d66b4bea84833 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss <erdnaxe@crans.org> Date: Sun, 10 May 2020 10:46:47 +0200 Subject: [PATCH] Fix compatibility with SSH config parsing --- cpasswords/remote.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cpasswords/remote.py b/cpasswords/remote.py index d71deb8..aaec0db 100644 --- a/cpasswords/remote.py +++ b/cpasswords/remote.py @@ -31,15 +31,19 @@ def create_ssh_client(host, password=None): """ # Create SSH client with system host keys and agent client = SSHClient() + # Load config file and use the right username try: - config = SSHConfig.from_file(Path.home().joinpath(".ssh/config").open()) - username = config.lookup(host)["user"] + config = SSHConfig() + config.parse(Path.home().joinpath(".ssh/config").open()) + username = config.lookup(host).get("user", None) except FileNotFoundError: username=None - except KeyError: - username=None + + # Load system private keys client.load_system_host_keys() + + # Connect try: client.connect(host, username=username, password=password) except PasswordRequiredException: -- GitLab