Skip to content

Instantly share code, notes, and snippets.

@alesr
Created October 7, 2015 15:06
Show Gist options
  • Save alesr/4fa2725994f6c1622594 to your computer and use it in GitHub Desktop.
Save alesr/4fa2725994f6c1622594 to your computer and use it in GitHub Desktop.
func (p *Project) insertSshkey() {
homeDir := fileUtil.FindUserHomeDir()
cmd := exec.Command("cat", homeDir+"/.ssh/"+p.sshkey.name+".pub", "|", "ssh", p.projectname.name+"@"+p.host.name, "'cat", ">>", "~/.ssh/authorized_keys'")
err := cmd.Run()
if err != nil {
...
}
}
@alesr
Copy link
Author

alesr commented Oct 8, 2015

Solução:

keyFile, err := os.Open(fileUtil.FindUserHomeDir() + sep + ".ssh" + sep + p.sshkey.name + ".pub")
if err != nil {
    log.Fatal(err)
}

cmd := exec.Command("ssh", p.projectname.name+"@"+p.host.name, "cat >> ~/.ssh/authorized_keys")
cmd.Stdin = keyFile

out, err := cmd.CombinedOutput()
if err != nil {
    fmt.Println(string(out))
    log.Fatal(err)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment