@@ -497,47 +497,55 @@ def cancel(self):
497497
498498 self ._cancelled = True
499499
500- def get_ipv4_ssh_command (self , user : str = "root" ) -> str :
500+ def get_ipv4_ssh_command (self , user : Union [ str , None ] = "root" ) -> str :
501501 """
502502 Construct an SSH command required to connect to the Pi using SSH over IPv4
503503 """
504+ if user is None :
505+ return f"ssh -p { self .ipv4_ssh_port } { self .ipv4_ssh_hostname } "
504506 return f"ssh -p { self .ipv4_ssh_port } { user } @{ self .ipv4_ssh_hostname } "
505507
506- def get_ipv6_ssh_command (self , * , user : str = "root" , numeric : bool = False ) -> str :
508+ def get_ipv6_ssh_command (
509+ self , * , user : Union [str , None ] = "root" , numeric : bool = False
510+ ) -> str :
507511 """
508512 Construct an SSH command required to connect to the Pi using SSH over IPv6
509513 """
510514 if numeric :
515+ if user is None :
516+ return f"ssh [{ self .ipv6_address .compressed } ]"
511517 return f"ssh { user } @[{ self .ipv6_address .compressed } ]"
512518 else :
519+ if user is None :
520+ return f"ssh { self .ipv6_ssh_hostname } "
513521 return f"ssh { user } @{ self .ipv6_ssh_hostname } "
514522
515- def get_ipv4_ssh_config (self , user : str = "root" ) -> str :
523+ def get_ipv4_ssh_config (self , user : Union [ str , None ] = "root" ) -> str :
516524 """
517525 Construct a string containing the IPv4 SSH config for the Pi. The contents could be added to
518526 an SSH config file for easy access to the Pi.
519527 """
520- return f""" Host { self .name }
521- user { user }
522- port { self .ipv4_ssh_port }
523- hostname { self .ipv4_ssh_hostname }
524- """ . strip ()
528+ host_line = f" Host { self .name } \n "
529+ user_line = f" user { user } \n " if user else ""
530+ port_line = f" port { self .ipv4_ssh_port } \n "
531+ hostname_line = f" hostname { self .ipv4_ssh_hostname } "
532+ return host_line + user_line + port_line + hostname_line
525533
526534 def get_ipv6_ssh_config (
527535 self ,
528536 * ,
529- user : str = "root" ,
537+ user : Union [ str , None ] = "root" ,
530538 numeric : bool = False ,
531539 ) -> str :
532540 """
533541 Construct a string containing the SSH config for the Pi. The contents could be added to an
534542 SSH config file for easy access to the Pi.
535543 """
536544 hostname = self .ipv6_address .compressed if numeric else self .ipv6_ssh_hostname
537- return f""" Host { self .name }
538- user { user }
539- hostname { hostname }
540- """ . strip ()
545+ host_line = f" Host { self .name } \n "
546+ user_line = f" user { user } \n " if user else ""
547+ hostname_line = f" hostname { hostname } "
548+ return host_line + user_line + hostname_line
541549
542550 def add_ssh_keys (self , ssh_keys : SSHKeySources ) -> set [str ]:
543551 """
0 commit comments