diff --git a/pkgs/clan-cli/clan_cli/ssh/host.py b/pkgs/clan-cli/clan_cli/ssh/host.py index 0cfc6af7e..1eca93a68 100644 --- a/pkgs/clan-cli/clan_cli/ssh/host.py +++ b/pkgs/clan-cli/clan_cli/ssh/host.py @@ -41,6 +41,22 @@ class Host: self.command_prefix = self.host if not self.user: self.user = "root" + home = Path.home() + if home.exists() and os.access(home, os.W_OK): + control_path = home / ".ssh" + if not control_path.exists(): + try: + control_path.mkdir(exist_ok=True) + except OSError: + pass + else: + self.ssh_options["ControlMaster"] = "auto" + # Can we make this a temporary directory? + self.ssh_options["ControlPath"] = str( + control_path / "clan-%h-%p-%r" + ) + # We use a short ttl because we want to mainly re-use the connection during the cli run + self.ssh_options["ControlPersist"] = "1m" def __str__(self) -> str: return self.target diff --git a/pkgs/clan-cli/clan_cli/tests/test_ssh_remote.py b/pkgs/clan-cli/clan_cli/tests/test_ssh_remote.py index e141d4b09..279bc93f2 100644 --- a/pkgs/clan-cli/clan_cli/tests/test_ssh_remote.py +++ b/pkgs/clan-cli/clan_cli/tests/test_ssh_remote.py @@ -117,7 +117,9 @@ def test_parse_deployment_address( assert result.user == expected_user or ( expected_user == "" and result.user == "root" ) - assert result.ssh_options == expected_options + + for key, value in expected_options.items(): + assert result.ssh_options[key] == value def test_parse_ssh_options() -> None: