18

Ok, so I have tried this quite a few times and I'm sure this is very trivial but: I am trying to SSH via command line on Ubuntu into my VM (Centos6) with an RSA key-pair I created using key-gen.

I have created the key-pair and appended the public key to authorized_keys file and changed the permissions to 600. After I SCP'ed the private key to Ubuntu and tried to SSH using it and I always get:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

I have tried this 3x already and no luck. I can ping it but I can't seem to figure out why it's not taking the key I made. Any suggestions?

9
  • 1
    Quick things to check: Make sure you're using the right username (prepend user@ to the hostname if it's not the same as the username on the client), and see if it works with selinux off (it can prevent sshd from reading the authorized_keys file).
    – Tom Hunt
    Sep 2, 2015 at 22:06
  • @TomHunt, user is actually root. And I checked selinux, it is off.
    – ryekayo
    Sep 2, 2015 at 22:07
  • From which server you want to login ? you created key-pair on which server and which user ? you copied public key to which server and which user ?
    – heemayl
    Sep 2, 2015 at 22:08
  • @heemayl, I created the key pair on the Centos server (VM) and I scpd the private key to my PC in Ubuntu. I then cat the public key to authorized_keys in the .ssh directory (in Centos) and change the ownership to 600. After that point, i tried to connect with the private key but was unable to..
    – ryekayo
    Sep 2, 2015 at 22:10
  • Is the private key is saved as ~/.ssh/id_rsa in relevant account of ubuntu with a permission 600 ? also as you are conecting from ubuntu, you should do it other way around..you should generate the key-pair in ubuntu and copy the public key to ~/.ssh/id_rsa.pub in centos..also check the permission of ~/.ssh directory..
    – heemayl
    Sep 2, 2015 at 22:14

7 Answers 7

17

Run ssh with verbose mode (add as many -v as you need) and try to find out the reason.

For example

ssh -vvv user@host

You will get a debug output that helps you to find out the reason.

2
  • 4
    This does not provide an answer to the question; this is just troubleshooting advice.  Answers should be used for definitive solutions.  Diagnostic suggestions should be posted as comments (which can be later developed into an answer, pending the result of the tests).  You can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. Jan 19, 2016 at 1:23
  • 3
    This seems perfectly fine to me Jan 19, 2016 at 6:28
4

First generate the key-pair on your Ubuntu machine.

After, copy the contents of the generated .pub file in your ssh folder (~/.ssh/id_rsa) and paste it to the username/.ssh/id_rsaauthorized_keys file, on a new line, on your CentOS for the specific user you are logging in with.

0
2

I just had the same problem on ClearOS 7.2 while trying to login through SSH using RSA from OSX.

Turns out I had to add the filename of my private key (the one that resides on the client system, OSX in this case) on the client system to the /etc/ssh/ssh_config file (this is the ssh client config file on the client machine). Otherwise it just wouldn't look in that file eventhough it starts with id_rsa.

The line added was:

IdentityFile ~/.ssh/id_rsa.somecomputer

"somecomputer" is whatever the rest of the filename you might have is.

2

I had the same problem, I solved it like this:

On the ssh server, I uncommented, and put at yes the following values in /etc/ssh/sshd_config

 RSAAuthentication yes
 PubkeyAuthentication yes

And then:

sudo service sshd restart
1

If you tailf /var/log/auth.log on the server and login again, you should see the reason for the failure get logged. If not, kick up the verbosity in the SSH daemon config file to DEBUG and retry again. Often times it's related to file permissions.

3
  • This does not provide an answer to the question; this is just troubleshooting advice.  Answers should be used for definitive solutions.  Diagnostic suggestions should be posted as comments (which can be later developed into an answer, pending the result of the tests). Jan 19, 2016 at 1:25
  • 1
    The OP is indicating he does not know why his auth is failing. This log will answer that question. Jan 19, 2016 at 1:31
  • 1
    This seems perfectly fine to me Jan 19, 2016 at 6:28
0

I am facing the same problem, for me, first change the server(CentOS 7.9) sshd config and allow the password login:

PasswordAuthentication yes

and restart the sshd:

systemctl restart sshd

the next time you login, it will pop the password input. Just input your ssh password or using this command to add no password login:

ssh -p 22 root@{server-ip} 'mkdir -p .ssh && cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub
-1

I've had the same issue before - my key was moved to a different folder and I did not update the ssh_config file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .