Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a ssh key to remote server?

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 [email protected] still get report Permission denied (publickey).

like image 335
cqcn1991 Avatar asked Sep 09 '13 02:09

cqcn1991


2 Answers

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).

like image 53
Sascha Avatar answered Oct 18 '22 00:10

Sascha


To add your ssh-key to your ssh-agent you have to add it with:

ssh-add

After that ensure your key is added:

ssh-add -l

To fix your permission problem try:

chmod 0600 ~/.ssh/authorized_keys
like image 38
deagh Avatar answered Oct 18 '22 01:10

deagh