how to append public keys to remote host instead of copy it

You can also use ssh-copy-id, which is a tool to do exactly what you want: add one or more keys to the authorized_keys of a remote system.


Use ssh together with tee -a file:

< /root/.ssh/authorized_keys sshpass -p "$pass" ssh root@"$remote_host" "tee -a ~/.ssh/authorized_keys"

or ssh with cat >> file if you prefer:

< /root/.ssh/authorized_keys sshpass -p "$pass" ssh root@"$remote_host" "cat >> ~/.ssh/authorized_keys"

Both tee and cat will read from stdin, which is sent to ssh with < file.
The difference is, that tee, unlike >> will print what it appends.

Note: The double quotes are needed, otherwise the >> or ~ will be interpreted by your shell before sending it to ssh command.