Пример #1
0
// addKeys adds keys to akd as name.
func addKeys(akd *keys.SSHAuthorizedKeysDir, name string, force bool) error {
	k := []byte{}
	files := []*os.File{}

	if flag.NArg() > 0 {
		// read from files
		for _, fp := range flag.Args() {
			f, err := os.Open(fp)
			if err != nil {
				return err
			}
			defer f.Close()
			files = append(files, f)
		}
	} else {
		// read from stdin
		files = append(files, os.Stdin)
	}

	for _, f := range files {
		b, err := ioutil.ReadAll(f)
		if err != nil {
			return err
		}
		k = append(k, b...)
	}

	if !validKeys(k) {
		return fmt.Errorf("key(s) invalid.")
	}

	return akd.Add(name, k, *flagReplace, force)
}
Пример #2
0
// printKeys prints all the keys currently managed.
func printKeys(akd *keys.SSHAuthorizedKeysDir) error {
	stdout("All keys for %s", *flagUser)
	return akd.WalkKeys(func(k *keys.SSHAuthorizedKey) error {
		if !k.Disabled {
			cmd := exec.Command("ssh-keygen", "-l", "-f", k.Path)
			out, err := cmd.CombinedOutput()
			if err != nil {
				return err
			}
			stdout("%s: %s", k.Name, string(out))
		}
		return nil
	})
}