Skip to content

Commit

Permalink
write knownhosts like openssh
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnywong committed Mar 3, 2024
1 parent 82a80cb commit cee1fa4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tssh/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ func writeKnownHost(path, host string, remote net.Addr, key ssh.PublicKey) error
if err := ensureNewline(file); err != nil {
return err
}
return knownhosts.WriteKnownHost(file, host, remote, key)

hostNormalized := knownhosts.Normalize(host)
if strings.ContainsAny(hostNormalized, "\t ") {
return fmt.Errorf("host '%s' contains spaces", hostNormalized)
}
line := knownhosts.Line([]string{hostNormalized}, key) + "\n"
return writeAll(file, []byte(line))
}

func addHostKey(path, host string, remote net.Addr, key ssh.PublicKey, ask bool) error {
Expand Down

0 comments on commit cee1fa4

Please sign in to comment.