Created
October 7, 2015 15:06
-
-
Save alesr/4fa2725994f6c1622594 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
... | |
} | |
} |
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
pensando somente nessa função, tenho uma alternativa com
ssh-copy-id
:tanto a lógica do
identity
quanto oaddress
poderiam estar dentro da struct ( se fizer sentido ), indo para algo como:assim você só tem um lugar para fazer toda essa lógica e ficando muito mais fácil de testar.