forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh.go
32 lines (24 loc) · 715 Bytes
/
ssh.go
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
28
29
30
31
32
package acsengine
import (
"crypto/rand"
"crypto/rsa"
"fmt"
"github.com/Azure/acs-engine/pkg/helpers"
"github.com/Azure/acs-engine/pkg/i18n"
)
// CreateSaveSSH generates and stashes an SSH key pair.
func CreateSaveSSH(username, outputDirectory string, s *i18n.Translator) (privateKey *rsa.PrivateKey, publicKeyString string, err error) {
privateKey, publicKeyString, err = helpers.CreateSSH(rand.Reader, s)
if err != nil {
return nil, "", err
}
privateKeyPem := privateKeyToPem(privateKey)
f := &FileSaver{
Translator: s,
}
err = f.SaveFile(outputDirectory, fmt.Sprintf("%s_rsa", username), privateKeyPem)
if err != nil {
return nil, "", err
}
return privateKey, publicKeyString, nil
}