For the sake of having security up to scratch on my LAMP server I generated ssh keys and tried to pair them with my server. Sadly it failed on server's side.

Here's the steps I followed:

typed command ssh-keygen -t rsa

Entered out prompts for passphrase (these are optional) and I left them blank.

It successfully generated public and private keys.

Typed ssh-copy-id root@my_server_id

Was prompted for root password. Entered, however I got error line saying "Permission denied. Try again".

I'm 100% sure about the password but still get this error and when I try to login into my server I get prompted for password and access is granted but not for keys ???

What can I do ? I can login into my server but can't pair ssh keys with my server.

  • post the whole output you are getting from ssh-copy-id. In recent versions it is quite clever and connects two times if I recall correctly. – Jakuje May 6 '17 at 20:44
  • Is the root account enabled? is password-based SSH login permitted for root? – steeldriver May 6 '17 at 21:29
  • This is the output from ssh-copy-id root@server_ip : /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@192.xxx.x.x's password: and when I enter root password it says permission denied and try again. I'm certain I'm missing something here because at this point I should be prompted on server-side to confirm pairing. The pairing was successful when I was doing this x months ago. – Mark Alexa May 7 '17 at 6:49
  • To answer your question, Steeldriver, I suppose root account is always enabled by default. – Mark Alexa May 7 '17 at 6:51

first of all, please try to log in as root over ssh with -vv eg:

ssh root@my_server_id -vv

I think it will tell you what exactly is wrong with your permissions. Probably your persmissions for .ssh directory are too wide and ssh does not like this at all :)

I think your /root/.ssh directory must have permissions set to 700

chmod 700 /root/.ssh

and file .ssh/authorized_keys should be set to 600

chmod 600 /root/.ssh/authorized_keys

  • Strange, when I typed sudo chmod 700 /root/.ssh it said "no such file or directory" ??? – Mark Alexa May 7 '17 at 19:34
  • Here's the full output from ssh root@my_server_id -vv: codeshare.io/50Aqgv – Mark Alexa May 7 '17 at 19:40

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.