I'm currently putting together a quick script that deploys multiple vagrant machines locally for dev purposes. Par of the procedure consists of adding the ssh key to the vagrant boxes.
So far, getting the path of the ssh keys is fairly easy:
vagrant ssh-config | grep IdentityFile | awk '{print $2}'
It gives the expected output:
/Users/admin/vms/.vagrant/machines/deploy-node.vagrant/virtualbox/private_key /Users/admin/vms/.vagrant/machines/backend-node.vagrant/virtualbox/private_key /Users/admin/vms/.vagrant/machines/app-node.vagrant/virtualbox/private_key
However, piping the result to ssh-add throws an exception:
ssh_askpass: exec(/usr/X11R6/bin/ssh-askpass): No such file or directory
When I manually type the commands one by one, the ssh-add works OK:
ssh-add /Users/admin/vms/.vagrant/machines/deploy-node.vagrant/virtualbox/private_key
Identity added...
Therefore, I believe the issue comes from the result of awk that returns a block of 3 lines instead of 3 times a line to the pipe.
This suspicion can be confirmed by issuing:
vagrant ssh-config | grep IdentityFile | awk '{print $2}' | wc -l
that returns 3 when I would expect to get 3 times the 1 value.
would someone know how to split the result of the awk so the ssh-add works properly?
awk '{print $2"\n"}'and let me know if this works. – Videonauth Oct 05 '18 at 06:55ssh-addhandles piping – E. Jaep Oct 05 '18 at 06:58