Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 7158ecb

Browse files
authored
Merge pull request #34 from keybase/david/create-dot-ssh-if-not-exist
Automatically create ~/.ssh/ prior to attempting to write a key to it
2 parents d65a202 + 861a902 commit 7158ecb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/cmd/kssh/kssh.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,15 @@ func isValidCert(keyPath string) bool {
291291
// Provision a new signed SSH key with the given config
292292
func provisionNewKey(config kssh.ConfigFile, keyPath string) error {
293293
log.Debug("Generating a new SSH key...")
294-
err := sshutils.GenerateNewSSHKey(keyPath, true, false)
294+
295+
// Make ~/.ssh/ in case it doesn't exist
296+
err := kssh.MakeDotSSH()
297+
if err != nil {
298+
return err
299+
}
300+
301+
// Generate the key itself and read it
302+
err = sshutils.GenerateNewSSHKey(keyPath, true, false)
295303
if err != nil {
296304
return fmt.Errorf("Failed to generate a new SSH key: %v", err)
297305
}
@@ -300,6 +308,7 @@ func provisionNewKey(config kssh.ConfigFile, keyPath string) error {
300308
return fmt.Errorf("Failed to read the SSH key from the filesystem: %v", err)
301309
}
302310

311+
// Provision the key
303312
randomUUID, err := uuid.NewRandom()
304313
if err != nil {
305314
return fmt.Errorf("Failed to generate a new UUID for the SignatureRequest: %v", err)
@@ -315,6 +324,7 @@ func provisionNewKey(config kssh.ConfigFile, keyPath string) error {
315324
}
316325
log.Debug("Received signature from the CA!")
317326

327+
// Write it to ~/.ssh
318328
err = ioutil.WriteFile(shared.KeyPathToCert(keyPath), []byte(resp.SignedKey), 0600)
319329
if err != nil {
320330
return fmt.Errorf("Failed to write new SSH key to disk: %v", err)

0 commit comments

Comments
 (0)