Reputation: 21573
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).
Upvotes: 20
Views: 55320
Reputation: 1041
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 -f -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.
Upvotes: 57
Reputation: 912
You can also use pssh
utility (Paralell SSH Tools, see Github repo).
Create a file with all the hostnames you want to add, then run:
pssh -h [hostsfile] -P 'echo "sshkeystringBLARG etc..." >> /home/[user]/.ssh/authorized_keys'
You can modify the command accordingly.
Upvotes: -5
Reputation: 2732
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
Upvotes: 4