Merge pull request #19510 from baude/errorifkeyexists

Fail if ssh key exists
This commit is contained in:
OpenShift Merge Robot 2023-08-05 12:27:14 +02:00 committed by GitHub
commit 38b20bda29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -20,6 +20,10 @@ var sshCommand = []string{"ssh-keygen", "-N", "", "-t", "ed25519", "-f"}
// CreateSSHKeys makes a priv and pub ssh key for interacting
// the a VM.
func CreateSSHKeys(writeLocation string) (string, error) {
// If the SSH key already exists, hard fail
if _, err := os.Stat(writeLocation); err == nil {
return "", fmt.Errorf("SSH key already exists: %s", writeLocation)
}
if err := os.MkdirAll(filepath.Dir(writeLocation), 0700); err != nil {
return "", err
}