[SOLVED] Can't connect via Pubkey to my CentOS VM

Support for security such as Firewalls and securing linux
Post Reply
100s
Posts: 9
Joined: 2019/04/01 03:58:22

[SOLVED] Can't connect via Pubkey to my CentOS VM

Post by 100s » 2019/04/01 04:21:21

Hi, I've set up a CentOS virtual machine using VMware 15 on my Windows 10 host.The idea is to be able to connect to the CentOS machine using a crypto key instead of a password.

So I powered the machine on and accessed it directly into VMware, created a .ssh dir under ~, which received the permission 700. (drwx------).

Then I opened Windows CMD on the host machine, executed ssh-keygen to generate the key pair:
C:\Users\me\.ssh\id_rsa
C:\Users\me\.ssh\id_rsa.pub
First I made sure I was the sole owner of the C:\users\me\.ssh folder; I read it could cause problems if more entities had permission to read/write/execute on that folder.

Afterwards, I opened the public key (C:\Users\me\.ssh\id_rsa.pub) with a text editor and copied its contents, then, back at the console, I logged in the virtual machine again.

Next, I created the ~/.ssh/autorized_keys file, edited and pasted the contents stored on the clipboard (the key C:\Users\me\.ssh\id_rsa.pub). Chmoded ~/.ssh/autorized_keys to 600.

After that I proceeded to editing the /etc/ssh/sshd_config file, changing the following:

Code: Select all

PubkeyAuthentication yes
PasswordAuthentication no
Then exited and tried logging in again, this time using ssh me@192.168.1.15 -i C:\Users\me\.ssh\id_rsa

Still, it keeps asking for my password.

I visited this page and performed the final step:

Code: Select all

restorecon -Rv ~/.ssh
Still nothing. What did I miss?

p.s. this is my kernel info: Linux me 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Last edited by 100s on 2019/04/01 07:38:54, edited 1 time in total.

User avatar
avij
Posts: 3039
Joined: 2010/12/01 19:25:52
Location: Helsinki, Finland
Contact:

Re: Can't connect via Pubkey to my CentOS VM

Post by avij » 2019/04/01 04:31:26

100s wrote:
2019/04/01 04:21:21
Next, I created the ~/.ssh/autorized_keys file, edited and pasted the contents stored on the clipboard (the key C:\Users\me\.ssh\id_rsa.pub). Chmoded ~/.ssh/autorized_keys to 600.
This should be authorized_keys.

Also see if your /var/log/secure has anything related to this.

100s
Posts: 9
Joined: 2019/04/01 03:58:22

[SOLVED] Can't connect via Pubkey to my CentOS VM

Post by 100s » 2019/04/01 07:38:04

Oh my God, I'm sorry that all the problem came from a typo.
Yes, that was it.
Nothing that seems unusual on the /var/log/secure except the notice that the password had been accepted – meaning the key was not used. I closed the session and logged in again, now I can see the mention of the pubkey being accepted instead of the password.
Again, sorry, but thanks!

Post Reply