diff --git a/forwarding.py b/forwarding.py index 1d1a410..5c14458 100644 --- a/forwarding.py +++ b/forwarding.py @@ -45,6 +45,6 @@ def cmd_forwarding(): click.Abort('Failed set iptables rule') logging.info("Setting default route on device via ssh") - result = run_ssh_command(cmd=['sudo -S route add default gw 172.16.42.2']) + result = run_ssh_command(cmd=['sudo -S route add default gw 172.16.42.2'], alloc_tty=True) if result.returncode != 0: click.Abort('Failed to add gateway over ssh') diff --git a/ssh.py b/ssh.py index c9787c8..48c212a 100644 --- a/ssh.py +++ b/ssh.py @@ -16,14 +16,14 @@ from exec.cmd import run_cmd @click.option('--port', '-p', help='the SSH port', type=int, default=SSH_DEFAULT_PORT) def cmd_ssh(cmd: list[str], user: str, host: str, port: int): """Establish SSH connection to device""" - run_ssh_command(list(cmd), user=user, host=host, port=port) + run_ssh_command(list(cmd), user=user, host=host, port=port, alloc_tty=True) def run_ssh_command(cmd: list[str] = [], user: Optional[str] = None, host: str = SSH_DEFAULT_HOST, port: int = SSH_DEFAULT_PORT, - alloc_tty: bool = False): + alloc_tty: bool = True): if not user: user = config.get_profile()['username'] keys = find_ssh_keys() @@ -34,13 +34,15 @@ def run_ssh_command(cmd: list[str] = [], extra_args += ['-v'] if alloc_tty: extra_args += ['-t'] - logging.info(f'Opening SSH connection to {(user + "@") if user else ""}{host} ({port})') + hoststr = f'{(user + "@") if user else ""}{host}' + logging.info(f'Opening SSH connection to {hoststr} ({port})') + logging.debug(f"ssh: trying to run {cmd} on {hoststr}") full_cmd = [ 'ssh', ] + extra_args + SSH_COMMON_OPTIONS + [ '-p', str(port), - f'{user}@{host}', + hoststr, '--', ] + cmd logging.debug(f"running cmd: {full_cmd}")