How to copy SSH public key to server

You have to copy your SSH public key to the server's SSH authorized_keys file in order to passwordlessly log in to the server. You can copy your SSH key to the server via any of these methods:

Copy SSH key using ssh-copy-id

  1. Use SSH's bundled command, ssh-copy-id
    $ ssh-copy-id user@host

    If you want to use other public key rather that then one in the default location, use the -i option as the following

    $ ssh-copy-id -i ~/.ssh/ username@host

Manually add SSH key to authorized_keys file

  1. Manually append the content of your public key file (normally ~/.ssh/ to the server's ~/.ssh/authorized_keys

Remotely add SSH key to authorized_keys via Bash script

  1. Using the following simple Bash script
    $ cat ~/.ssh/ | ssh user@host 'cat >> ~/.ssh/authorized_keys