Setup keypair with remote server

Create a key


Copying the public key to the server


Assumes that the user can authenticate with a password

ssh-copy-id username@remote_host


On client

cat ~/.ssh/

On server

mkdir -p ~/.ssh
echo public_key_string >> ~/.ssh/authorized_keys

Adding a key to the ssh-agent

For services like git, it may look to the ssh-agent to see that the appropriate key is present. To add a new key run

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/<keyname>


On Mac, the following will add the key to the keychain and tell the ssh-agent to always use the keychain.

ssh-add --apple-use-keychain ~/.ssh/[private-key]

And the following in .ssh/config. Many keys can be added by having more than one IdentityFile.

Host *
    UseKeychain yes
    AddKeysToAgent yes
    IdentityFile ~/.ssh/[private-key]