Permission denied (publickey) error right after generating the SSH keys

I know this question might have been asked before But I still cannot really find the answer, and the answer in my case should be simple.

So what have I done is in my ECS server I created a new user and gave it sudo privilege by assigning it to the sudo group. Then I change some of the sshd_config parameter:

  1. change port from 22 to another
  2. PermitRootLogin from “yes” to “no”
  3. PasswordAuthentication from “yes” to “no”

And then I generate SSH key by ssh-keygen -t rsa
and copy it to the authorized_keys by ssh-copy-id user@ipAddress

and then I restart the server, ssh login to the server and get the Permission denied (publickey) error.

In the server /home/user/.ssh folder lies authorized_keys, and id_rsa three files. But in my local machine .ssh folder there is no key file.

So where is the problem?

Asked By: Frostless


Detailed instructions how to connect to SSH server can be found here

From your question it is clear that you should do the following:

How To Create SSH Keys

SSH keys should be generated on the computer you wish to log in from. This is usually your local computer.

Enter the following into the command line:

ssh-keygen -t rsa

Press enter to accept the defaults. Your keys will be created at ~/.ssh/ and ~/.ssh/id_rsa.

have the following files in the ~/.ssh directory in the client machine:

-rw------- 1 demo demo 1679 Sep  9 23:13 id_rsa
-rw-r--r-- 1 demo demo  396 Sep  9 23:13

As you can see, the id_rsa file is readable and writable only to the owner. This is how it should be to keep it secret.

The file, however, can be shared and has permissions appropriate for this activity.

On the server side, you should have the public key (not the private key).

Answered By: Yaron
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.