I am writing a bash script that should start a serf agent(http://www.serfdom.io/intro/index.html) on a remote machine via ssh. I have set up rsa keys using...
ssh-key-gen -t rsa -b 4096 ssh-copy-id -i ~/.ssh/id_rsa.pub <remote-host>
And I can ssh into the remote machine without a password from the terminal. This is the call I'm making in the script
ssh <user>@<hostname> "serf agent -node database -event-handler user:database_install=~/serf_install_db_handler.sh"
But when the script is executing, I have to use this command in order to run it without password prompt...
ssh -i ~/.ssh/id_rsa.pub <remote-host> <command>
Why do I have to do this in the script when I don't need to do it in the terminal?