//go:build linux || freebsd // +build linux freebsd package sftp import ( "fmt" "os" "path/filepath" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/knownhosts" ) func hostKeyCallback(knownHostsPath string, insecure bool) (ssh.HostKeyCallback, error) { if insecure { return ssh.InsecureIgnoreHostKey(), nil } if knownHostsPath == "" { home, err := os.UserHomeDir() if err != nil { return nil, fmt.Errorf("known_hosts: %w", err) } knownHostsPath = filepath.Join(home, ".ssh", "known_hosts") } if _, err := os.Stat(knownHostsPath); err != nil { return nil, fmt.Errorf("known_hosts file not found: %s (use --ssh-insecure to skip host key check)", knownHostsPath) } return knownhosts.New(knownHostsPath) }