mirror of
https://github.com/containers/podman.git
synced 2025-06-23 10:38:20 +08:00
Fail if ssh key exists
when init'ing a machine, if the ssh key already exists, then we get a somewhat oblique error. here we make it clear what the problem was and early return. Signed-off-by: Brent Baude <bbaude@redhat.com> [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user