// config.SSHAuthorizedKeys sets the "core" user, the other sets the root func setKey(config *cloudinit.CloudConfig, key string) *cloudinit.CloudConfig { config.SSHAuthorizedKeys = append(config.SSHAuthorizedKeys, key) // set the password for both users if len(config.Users) == 0 { root := cloudinit.User{ Name: "root", } root.SSHAuthorizedKeys = append(root.SSHAuthorizedKeys, key) config.Users = append(config.Users, root) } else { config.Users[0].SSHAuthorizedKeys = append(config.Users[0].SSHAuthorizedKeys, key) } return config }
func handleShadow(contents string, scripts_dir string) (*cloudinit.CloudConfig, error) { config := cloudinit.CloudConfig{} passwd := contents // root:$1$NyBnu0Gl$GBoj9u6lx3R8nyqHuxPwz/:15839:0::::: re := regexp.MustCompile("root:([^:]+):.+\n") keys := re.FindStringSubmatch(passwd) if len(keys) == 2 { passwd_hash := keys[1] // set the password for both users root := cloudinit.User{ Name: "root", PasswordHash: passwd_hash, } config.Users = append(config.Users, root) core := cloudinit.User{ Name: "core", PasswordHash: passwd_hash, } config.Users = append(config.Users, core) } return &config, nil }