add client creation logic

This commit is contained in:
William Banfield
2022-11-30 12:46:00 -05:00
parent b0be713546
commit b7fccf0138
2 changed files with 32 additions and 3 deletions

View File

@@ -22,12 +22,24 @@ func Exec(cfg *ssh.ClientConfig, addr, cmd string) error {
return nil
}
func NewClientConfig(key string) (*ssh.ClientConfig, error) {
func NewClientConfig(keyFile string) (*ssh.ClientConfig, error) {
hkc, err := knownhosts.New(filepath.Join(os.Getenv("HOME"), ".ssh", "known_hosts"))
if err != nil {
return nil, err
}
key, err := os.ReadFile(keyFile)
if err != nil {
return nil, err
}
signer, err := ssh.ParsePrivateKey(key)
if err != nil {
return nil, err
}
return &ssh.ClientConfig{
HostKeyCallback: hkc,
Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer),
},
HostKeyAlgorithms: []string{ssh.KeyAlgoED25519},
}, nil
}