Skip to content

Commit

Permalink
polish commands
Browse files Browse the repository at this point in the history
  • Loading branch information
wreulicke committed May 20, 2020
1 parent 937c7cb commit d5c4324
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion key.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var AddKeyCommandTmpl = `u=$(getent passwd {{.user}}) && x=$(echo $u |cut -d: -f6) || exit 1
install -d -m700 -o{{.user}} ${x}/.ssh; grep '{{.publicKey}}' ${x}/.ssh/authorized_keys && exit 0
install -d -m700 -o{{.user}} ${x}/.ssh; grep '{{.publicKey}}' ${x}/.ssh/authorized_keys > /dev/null 2>/dev/null && exit 0
echo '{{.publicKey}}'| tee -a ${x}/.ssh/authorized_keys
`

Expand Down
5 changes: 3 additions & 2 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ssm"
)

var createUserTmpl = `sudo useradd %s
var createUserTmpl = `sudo useradd %s || exit 1
sudo usermod -aG adm,wheel %s
echo "%s ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/%s
`

func CreateUser(ssmCli *ssm.Client, instanceIds []string, user string) error {
Expand All @@ -21,7 +22,7 @@ func CreateUser(ssmCli *ssm.Client, instanceIds []string, user string) error {
DocumentName: aws.String("AWS-RunShellScript"),
Comment: aws.String("create user"),
Parameters: map[string][]string{
"commands": []string{fmt.Sprintf(createUserTmpl, user, user)},
"commands": []string{fmt.Sprintf(createUserTmpl, user, user, user, user)},
},
})
res, err := req.Send(ctx)
Expand Down

0 comments on commit d5c4324

Please sign in to comment.