Skip to content

Commit

Permalink
Dont add ControlMaster ssh entries on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrice Normandin <[email protected]>
  • Loading branch information
lebrice committed Nov 6, 2023
1 parent 5c2fd71 commit 845e313
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions milatools/cli/init_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import difflib
from logging import getLogger as get_logger
from pathlib import Path
import sys

import questionary as qn

Expand Down Expand Up @@ -39,21 +40,29 @@ def setup_ssh_config(
# sure that the directory actually exists.
control_path_dir.expanduser().mkdir(exist_ok=True, parents=True)

if sys.platform == "win32":
ssh_multiplexing_config = {}
else:
ssh_multiplexing_config = {
# Tries to reuse an existing connection, but if it fails, it will create a new one.
"ControlMaster": "auto",
# This makes a file per connection, like [email protected]:2222
"ControlPath": str(control_path_dir / r"%r@%h:%p"),
# persist for 10 minutes after the last connection ends.
"ControlPersist": 600,
}

_add_ssh_entry(
ssh_config,
"mila",
host="mila",
Host=None,
HostName="login.server.mila.quebec",
User=username,
PreferredAuthentications="publickey,keyboard-interactive",
Port=2222,
ServerAliveInterval=120,
ServerAliveCountMax=5,
# Tries to reuse an existing connection, but if it fails, it will create a new one.
ControlMaster="auto",
# This makes a file per connection, like [email protected]:2222
ControlPath=str(control_path_dir / r"%r@%h:%p"),
# persist for 10 minutes after the last connection ends.
ControlPersist=600,
**ssh_multiplexing_config,
)

_add_ssh_entry(
Expand Down Expand Up @@ -97,12 +106,7 @@ def setup_ssh_config(
HostName="%h",
User=username,
ProxyJump="mila",
# Tries to reuse an existing connection, but if it fails, it will create a new one.
ControlMaster="auto",
# This makes a file per connection, like [email protected]:2222
ControlPath=str(control_path_dir / r"%r@%h:%p"),
# persist for 10 minutes after the last connection ends.
ControlPersist=600,
**ssh_multiplexing_config,
)

new_config = ssh_config.cfg.config()
Expand Down Expand Up @@ -206,6 +210,7 @@ def _add_ssh_entry(
ssh_config: SSHConfig,
host: str,
Host: str | None = None,
*,
_space_before: bool = True,
_space_after: bool = False,
**entry,
Expand Down

0 comments on commit 845e313

Please sign in to comment.