There is already a command in the ssh suite to do this automatically for you. I.e log into a remote host and add the public key to that computers authorized_keys file.
ssh-copy-id -i /path/to/key/file [email protected]
If the key you are installing is ~/.ssh/id_rsa
then you can even drop the -i
flag completely.
Much better than manually doing it!