This commit is contained in:
Jeshua Lin 2025-03-16 05:32:25 +08:00 committed by GitHub
commit 4ba19942e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 3 deletions

View File

@ -44,8 +44,8 @@ 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/{{.SSHCertFilePath}}-cf_key
CertificateFile ~/.cloudflared/%h-cf_key-cert.pub CertificateFile ~/.cloudflared/{{.SSHCertFilePath}}-cf_key-cert.pub
{{- else}} {{- else}}
Host {{.Hostname}} Host {{.Hostname}}
ProxyCommand {{.Cloudflared}} access ssh --hostname %h ProxyCommand {{.Cloudflared}} access ssh --hostname %h
@ -412,10 +412,11 @@ func sshConfig(c *cli.Context) error {
ShortLivedCerts bool ShortLivedCerts bool
Hostname string Hostname string
Cloudflared string Cloudflared string
SSHCertFilePath string
} }
t := template.Must(template.New("sshConfig").Parse(sshConfigTemplate)) t := template.Must(template.New("sshConfig").Parse(sshConfigTemplate))
return t.Execute(os.Stdout, 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(), SSHCertFilePath: token.GenerateSSHCertFilePathFromURL(url.Parse(ensureURLScheme(hostname)), sshgen.keyName)})
} }
// sshGen generates a short lived certificate for provided hostname // sshGen generates a short lived certificate for provided hostname