summaryrefslogtreecommitdiff
path: root/pkg/machine/keys.go
blob: 319fc2b4e2f72cdf0211024f1239b3aa52e43103 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// +build amd64,!windows arm64,!windows

package machine

import (
	"io/ioutil"
	"os/exec"
	"strings"
)

// CreateSSHKeys makes a priv and pub ssh key for interacting
// the a VM.
func CreateSSHKeys(writeLocation string) (string, error) {
	if err := generatekeys(writeLocation); err != nil {
		return "", err
	}
	b, err := ioutil.ReadFile(writeLocation + ".pub")
	if err != nil {
		return "", err
	}
	return strings.TrimSuffix(string(b), "\n"), nil
}

// generatekeys creates an ed25519 set of keys
func generatekeys(writeLocation string) error {
	return exec.Command("ssh-keygen", "-N", "", "-t", "ed25519", "-f", writeLocation).Run()
}