Linux – How to add a ssh key to remote server

linuxsshssh-keys

In my VPS, run ssh-add -l and it returns: The agent has no identities.
but I have run cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys' previously

I then run ssh-add ~/.ssh/authorized_keys
it returns @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/deployer/.ssh/authorized_keys' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.

and ssh git@github.com still get report Permission denied (publickey).

Best Answer

The currently most up voted answer is plainly wrong as it fails to understand the question. OP is asking how to authorize a key on a remote server, not how to add a key to your local ssh-agent.

To add a key to a remote server use the ssh-copy-id command from your local PC:

ssh-copy-id -i path/to/key.pub username@remoteHost

This adds the public key located at path/to/key.pub with the correct permission to the server at remoteHost using username as login name. Note that this also seems to require the private key next to the public key (the path/to/key file in this example).