@@ -356,9 +356,15 @@ func (r *RootCmd) configSSH() *serpent.Command {
356
356
if sshConfigOpts .disableAutostart {
357
357
flags += " --disable-autostart=true"
358
358
}
359
+ if coderdConfig .HostnamePrefix != "" {
360
+ flags += " --ssh-host-prefix " + coderdConfig .HostnamePrefix
361
+ }
362
+ if coderdConfig .HostnameSuffix != "" {
363
+ flags += " --hostname-suffix " + coderdConfig .HostnameSuffix
364
+ }
359
365
defaultOptions = append (defaultOptions , fmt .Sprintf (
360
- "ProxyCommand %s %s ssh --stdio%s --ssh-host-prefix %s %%h" ,
361
- escapedCoderBinary , rootFlags , flags , coderdConfig . HostnamePrefix ,
366
+ "ProxyCommand %s %s ssh --stdio%s %%h" ,
367
+ escapedCoderBinary , rootFlags , flags ,
362
368
))
363
369
}
364
370
@@ -391,7 +397,7 @@ func (r *RootCmd) configSSH() *serpent.Command {
391
397
}
392
398
393
399
hostBlock := []string {
394
- "Host " + coderdConfig . HostnamePrefix + "*" ,
400
+ sshConfigHostLinePatterns ( coderdConfig ) ,
395
401
}
396
402
// Prefix with '\t'
397
403
for _ , v := range configOptions .sshOptions {
@@ -837,3 +843,19 @@ func diffBytes(name string, b1, b2 []byte, color bool) ([]byte, error) {
837
843
}
838
844
return b , nil
839
845
}
846
+
847
+ func sshConfigHostLinePatterns (config codersdk.SSHConfigResponse ) string {
848
+ builder := strings.Builder {}
849
+ // by inspection, WriteString always returns nil error
850
+ _ , _ = builder .WriteString ("Host" )
851
+ if config .HostnamePrefix != "" {
852
+ _ , _ = builder .WriteString (" " )
853
+ _ , _ = builder .WriteString (config .HostnamePrefix )
854
+ _ , _ = builder .WriteString ("*" )
855
+ }
856
+ if config .HostnameSuffix != "" {
857
+ _ , _ = builder .WriteString (" *." )
858
+ _ , _ = builder .WriteString (config .HostnameSuffix )
859
+ }
860
+ return builder .String ()
861
+ }
0 commit comments