I'm trying to add a public key under my local $HOME/.ssh/ directory using Go.
I've been running multiple commands with this the same code without problem, but not for this particular one.
identity := fmt.Sprintf("cat %s/.ssh/%s.pub", fileUtil.FindUserHomeDir(), p.sshkey.name)
address := fmt.Sprintf("| ssh %s@%s 'cat >> ~/.ssh/authorized_keys', p.projectname.name, p.host.name)
cmd := exec.Command(identity, address)
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
Basically I'm trying to run:
cat /home/foo/.ssh/foobar.pub | ssh foo@bar.com 'cat >> ~/.shh/authorized_keys'"
Which works fine if I run it through the command line directly.
I want to run this program in different OS X machines, where some don't have ssh-copy-id installed. So, I'm not considering to use it.
But anyway, I'm open to other suggestions. Thank you in advance.