print 'Add to your ssh config' message on stdout

This commit is contained in:
Alex Vanderpot 2023-08-08 08:15:50 -07:00
parent 5f3cfe044f
commit 244a44fa2b
1 changed files with 22 additions and 15 deletions

View File

@ -35,10 +35,8 @@ const (
sshGenCertFlag = "short-lived-cert" sshGenCertFlag = "short-lived-cert"
sshConnectTo = "connect-to" sshConnectTo = "connect-to"
sshDebugStream = "debug-stream" sshDebugStream = "debug-stream"
sshConfigTemplate = ` sshConfigTemplateStdout = `
Add to your {{.Home}}/.ssh/config: {{- if .ShortLivedCerts -}}
{{- if .ShortLivedCerts}}
Match host {{.Hostname}} exec "{{.Cloudflared}} access ssh-gen --hostname %h" Match host {{.Hostname}} exec "{{.Cloudflared}} access ssh-gen --hostname %h"
ProxyCommand {{.Cloudflared}} access ssh --hostname %h ProxyCommand {{.Cloudflared}} access ssh --hostname %h
IdentityFile ~/.cloudflared/%h-cf_key IdentityFile ~/.cloudflared/%h-cf_key
@ -47,6 +45,9 @@ Match host {{.Hostname}} exec "{{.Cloudflared}} access ssh-gen --hostname %h"
Host {{.Hostname}} Host {{.Hostname}}
ProxyCommand {{.Cloudflared}} access ssh --hostname %h ProxyCommand {{.Cloudflared}} access ssh --hostname %h
{{end}} {{end}}
`
sshConfigTemplateStderr = `Add to your {{.Home}}/.ssh/config:
` `
) )
@ -372,8 +373,14 @@ func sshConfig(c *cli.Context) error {
Cloudflared string Cloudflared string
} }
t := template.Must(template.New("sshConfig").Parse(sshConfigTemplate)) tc := config{Home: os.Getenv("HOME"), ShortLivedCerts: genCertBool, Hostname: hostname, Cloudflared: cloudflaredPath()}
return t.Execute(os.Stdout, config{Home: os.Getenv("HOME"), ShortLivedCerts: genCertBool, Hostname: hostname, Cloudflared: cloudflaredPath()}) t := template.Must(template.New("sshConfig").Parse(sshConfigTemplateStderr))
err := t.Execute(os.Stderr, tc)
if err != nil {
return err
}
t = template.Must(template.New("sshConfig").Parse(sshConfigTemplateStdout))
return t.Execute(os.Stdout, tc)
} }
// sshGen generates a short lived certificate for provided hostname // sshGen generates a short lived certificate for provided hostname