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'
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.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ 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).
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).
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
Dude, use pssh. Create a file with all the hostnames you want to add the file to, then run something like:
pssh -h [hostsfile] -P 'echo "sshkeystringBLARG etc..." >> /home/[user]/.ssh/authorized_hosts'
You can modify the cmd accordingly and off you go.
Enjoy
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.