0

This is NOT about public key authorization, I know how to copy the public key and ssh that way. This is about the private key.

So I just created 2 VMs, they're connected through vagrant private network. One of them is called server01 the other is called server02.

I created user '01' on 'server01', and user '02' on 'server02'.

I ssh-keygen on both of them, so they each have id_rsa and id_rsa.pub.

I copy the contents of 01's id_rsa (the private key) into a file called 01key in 02's machine.

I then ssh into 01 from 02 with the following command: ssh -i 01key 01@10.9.8.11 And it asks me for the password....

Why? Isn't the whole point of connecting with the private key that you DON'T use passwords? I created a Linux server on AWS and it provided me with a private key for that particular instance and I was able to ssh -I key into it without it asking for the password, so what am I doing wrong?

I checked the permissions on the 01key file, and they're 600.

EDIT: All the answers are irrelevant. I know how to use the public key to connect through ssh, but that's not what I'm looking for.

I created a Linux instance on AWS and created an ssh keypair, then it only gave me the PRIVATE key, which I could use to connect to that AWS instance. That's what I'm talking about.

1

I copy the contents of 01's id_rsa (the private key) into a file called 01key in 02's machine.

Pubkey authentication doesn't work like that. You must copy user01's public key to

~user01/.ssh/authorized_keys

on server02. This is more easily done via the command:

ssh-copy-id user01@server02

I then ssh into 01 from 02 ...

That's the opposite, with this setup you can ssh from server01 to server02 passwordlessly.

... with the following command: ssh -I 01key 01@10.9.8.11

The -I flag specifies the PKCS#11 shared library. You probably meant -i to specify the identity. Anyway, this is unnecessary; just do

ssh user01@server02
  • I know how to use the pubkey to connect. I know how to use the ssh-copy-id command. The I was a typo. This does not answer my question. – iamAguest Aug 30 '18 at 6:11
1

To copy the public key to a server use:

ssh-copy-id user2@server

wich will copy (on current server):

/home/user1/.ssh/id_rsa.pub

into the file (on specified server):

/home/user2/.ssh/authorized_keys

This can also be done manually by appending public key:

cat /home/user1/.ssh/id_pub.rsa | ssh user2@server "cat >> /home/user2/.ssh/authorized_keys"

  • cat /home/user1/.ssh/id_pub.rsa pipes contents of user1's public key

  • ssh user2@server "[cmd]" execute specified command as user2 on specified server

  • cat >> /home/user2/.ssh/authorized_keys takes piped data and appends to file

1

You aren't supposed to copy the private key. It's id_rsa.pub you want, and usually you would put that in ~02/.ssh/authorized_keys.

  • Yes I was able to create a user called 01, and another called 02 on the other machine. The AWS server gave me it's private ssh key, which I used to connect to it without it asking for my password. I know how to ssh with the public key, with that method 02 would give his public key to 01 and append it to the authorized_keys file, and then 02 would connect to 01, but that's work on 01's part, which is not what happened on the AWS server. – iamAguest Aug 29 '18 at 15:33
  • Alright, I will be interested to read the answer if it's forthcoming. – flaysomerages Aug 29 '18 at 15:39
  • 1
    Now that you have two additional answers not substantially different from mine, one from a user of high rep. – flaysomerages Aug 29 '18 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.