SSH connection with .pub file

2019-07-31 10:20发布

问题:

I am given with id_rsa.pub from client. And I was told to connect to it. I tried adding the key with ssh-copy-id user@ec2-remoteserver.com

But it gave the error. Permission denied (publickey).

Then I thought of trying to connect with

ssh -i /c/Users/kdash/Desktop/id_rsa.pub user@ec2-instance.com

It now says the error

Load key "/c/Users/kdash/Desktop/id_rsa.pub": invalid format

Can anyone please help me understand how shall I add the given .pub key file and access to the remote server.

Earlier I had connected to servers with .pem files as such:

ssh -i /c/Users/kdash/Desktop/server.pem user@ec2-instance.com

I am not clear how .pub file can be used.

回答1:

Client should provide you the private key to connect to server.

I am sure client must have added the public key in their ~/.ssh/authorized_keys

Once client provide you the private-key file, then you can connect as

ssh -i <private-key> user@ec2-instance.com

See example here, remote machine is adding public key in ~/.ssh/authorized_keys and then user can connect to it using private key.

So I guess, you need private key file to connect to remote ssh server.

Remote machine should never add private key in ~/.ssh/authorized_keys.



标签: ssh