Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
e7d5a6b92b |
24
main.go
24
main.go
@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -51,7 +52,7 @@ Label:
|
|||||||
|
|
||||||
func createAutorizationFile(authorizedKeyFile string) error {
|
func createAutorizationFile(authorizedKeyFile string) error {
|
||||||
|
|
||||||
err := os.MkdirAll(filepath.Dir(authorizedKeyFile), 700)
|
err := os.MkdirAll(filepath.Dir(authorizedKeyFile), 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -207,10 +208,10 @@ func rootCmd(cmd *cobra.Command, args []string) error {
|
|||||||
userAuthorizedKeys = addSSHKeys(userAuthorizedKeys, etcAuthorizedKeys)
|
userAuthorizedKeys = addSSHKeys(userAuthorizedKeys, etcAuthorizedKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeSSHKeysFile(userAuthorizedKeyFile, userAuthorizedKeys)
|
return writeSSHKeysFile(user, userAuthorizedKeyFile, userAuthorizedKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeSSHKeysFile(authorizedKeyFile string, sshKeys []*sshKey) error {
|
func writeSSHKeysFile(u *user.User, authorizedKeyFile string, sshKeys []*sshKey) error {
|
||||||
if err := createAutorizationFile(authorizedKeyFile); err != nil {
|
if err := createAutorizationFile(authorizedKeyFile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -221,7 +222,22 @@ func writeSSHKeysFile(authorizedKeyFile string, sshKeys []*sshKey) error {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
return writeSSHKeys(f, sshKeys)
|
err = writeSSHKeys(f, sshKeys)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
uid, err := strconv.Atoi(u.Uid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
gid, err := strconv.Atoi(u.Gid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return os.Chown(authorizedKeyFile, uid, gid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeSSHKeys(w io.Writer, sshKeys []*sshKey) error {
|
func writeSSHKeys(w io.Writer, sshKeys []*sshKey) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user