···6363Once the connection is established, you can enter commands in the socat terminal6464where socat is running.65656666+## SSH Access for test machines {#sec-nixos-test-ssh-access}6767+6868+An SSH-based backdoor to log into machines can be enabled with6969+7070+```nix7171+{7272+ name = "…";7373+ nodes.machines = { /* … */ };7474+ sshBackdoor.enable = true;7575+}7676+```7777+7878+This creates a [vsock socket](https://man7.org/linux/man-pages/man7/vsock.7.html)7979+for each VM to log in with SSH. This configures root login with an empty password.8080+8181+When the VMs get started interactively with the test-driver, it's possible to8282+connect to `machine` with8383+8484+```8585+$ ssh vsock/3 -o User=root8686+```8787+8888+The socket numbers correspond to the node number of the test VM, but start8989+at three instead of one because that's the lowest possible9090+vsock number.9191+9292+On non-NixOS systems you'll probably need to enable9393+the SSH config from {manpage}`systemd-ssh-proxy(1)` yourself.9494+6695## Port forwarding to NixOS test VMs {#sec-nixos-test-port-forwarding}67966897If your test has only a single VM, you may use e.g.
···109109 help="the test script to run",110110 type=Path,111111 )112112+ arg_parser.add_argument(113113+ "--dump-vsocks",114114+ help="indicates that the interactive SSH backdoor is active and dumps information about it on start",115115+ action="store_true",116116+ )112117113118 args = arg_parser.parse_args()114119···141136 if args.interactive:142137 history_dir = os.getcwd()143138 history_path = os.path.join(history_dir, ".nixos-test-history")139139+ if args.dump_vsocks:140140+ driver.dump_machine_ssh()144141 ptpython.ipython.embed(145142 user_ns=driver.test_symbols(),146143 history_filename=history_path,
+15
nixos/lib/test-driver/src/test_driver/driver.py
···1111from typing import Any1212from unittest import TestCase13131414+from colorama import Style1515+1416from test_driver.errors import MachineError, RequestedAssertionFailed1517from test_driver.logger import AbstractLogger1618from test_driver.machine import Machine, NixStartScript, retry···177175 + ", ".join(list(general_symbols.keys()))178176 )179177 return {**general_symbols, **machine_symbols, **vlan_symbols}178178+179179+ def dump_machine_ssh(self) -> None:180180+ print("SSH backdoor enabled, the machines can be accessed like this:")181181+ print(182182+ f"{Style.BRIGHT}Note:{Style.RESET_ALL} this requires {Style.BRIGHT}systemd-ssh-proxy(1){Style.RESET_ALL} to be enabled (default on NixOS 25.05 and newer)."183183+ )184184+ names = [machine.name for machine in self.machines]185185+ longest_name = len(max(names, key=len))186186+ for num, name in enumerate(names, start=3):187187+ spaces = " " * (longest_name - len(name) + 2)188188+ print(189189+ f" {name}:{spaces}{Style.BRIGHT}ssh -o User=root vsock/{num}{Style.RESET_ALL}"190190+ )180191181192 def test_script(self) -> None:182193 """Run the test script"""