Ubuntu: SSH login using Ubuntu's terminal - Permission denied (publickey)



Question:

I'm using ubuntu system to login to remote server using ssh. SSH is configured in my system and I can see my public ssh key but when I try something like ssh xx.xx.xx.xx it throws error Permission denied (publickey).

For the IP address which I'm trying to access, ssh username is ec5-user without any password.

Do I have to switch to that user in my ubuntu terminal before using ssh xx.xx.xx.xx ? Using putty, I'm able to login from windows system.

If I do ssh-keygen -lf ~/.ssh/id_rsa.pub, it gives soething like

2048 aa:b5:51:76:de:42:12:78:a1:ff:9e:74:d8:7d:59:24  amit@amit-Inspiron-N5010 (RSA)  


Solution:1

Check .ssh folder permission (run ls -laR ~/.ssh):

.ssh folder should have 700, while private key 600 and the public one can have 644.

Moreover, you can have more information about the problem running ssh with full debug logs

ssh -vvv ...  


Solution:2

You're trying to ssh to ec5-user@xxx.xxx.xxx.xxx. OK, they way ssh works is as follows:

ssh xxx.xxx.xxx.xxx = ssh [my username]@xxx.xxx.xxx.xxx

ssh bob@xxx.xxx.xxx.xxx = ssh bob@xxx.xxx.xxx.xxx

So, you need to either log in to the same username, or you need to specify what username you're trying to ssh to.


Solution:3

If the comments above are correct that you are indeed getting Could not resolve hostname, this means that Ubuntu has no idea how to find the hostname you're giving it. Can you log in via the IP address?

If using the IP address works fine and you're having issues connecting to a hostname (which the error seems to indicate), you can modify your /etc/hosts file to include the node you are trying to connect to. Just enter the hostname and IP address you want it tied to like so:

EXAMPLE

   127.0.0.1       localhost     192.168.1.10    foo.mydomain.org       foo     192.168.1.13    bar.mydomain.org       bar     146.82.138.7    master.debian.org      master     209.237.226.90  www.opensource.org  

Fields of the entry are separated by any number of blanks and/or tab characters. Text from a "#" character until the end of the line is a comment, and is ignored. Host names may contain only alphanumeric characters, minus signs ("-"), and periods ("."). They must begin with an alphabetic character and end with an alphanumeric character. Optional aliases provide for name changes, alternate spellings, shorter hostnames, or generic hostnames (for example, localhost).

Source: http://manpages.ubuntu.com/manpages/lucid/man5/hosts.5.html


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »