0

I am trying to login into remote server without password using ssh but I am get the error:

Permission denied (publickey)

To copy .pub key to the server, I had:

PasswordAuthentication = yes (in the sshd_config file).

After I copied the .pub key, the i disabled the password in the ssh_config I had:

PasswordAuthentication = no

Now when I tried to ssh:

ssh 'server@192.168.xx.x'

I was getting the error:

Permission denied (publickey)

How can I solve the problem?

I have changed the authorized_keys permission, the .ssh/ permission and so on, but the problem persist. I have even used the ssh-agent $SHELL && ssh-add command.

6
  • What are the current permissions on the .ssh directory and the files therein on the server system? – Kusalananda Sep 19 '18 at 7:29
  • authorized_keys in remote host must be 644 – Archemar Sep 19 '18 at 7:40
  • 1
    using ssh -vvv will give more verbose output - but is the .pub key in the your authorized_keys file on the server you want to access? – fcbsd Sep 19 '18 at 9:18
  • How do you pass your private key? Using ssh-agent or ssh -i ? – Panki Sep 19 '18 at 9:51
  • @Panki They say they start a shell through the agent and then add the key with ssh-add. – Kusalananda Sep 19 '18 at 9:56
0

I always use below step to create new ssh connection to remote machines:

  1. Generate a new ssh key pair (just press enter until back to shell):

    localhost$ ssh-keygen -t rsa
    localhost$ cp .ssh/id_rsa.pub .ssh/authorized_keys
    
  2. Copying the newly created public key to remote machine:

    localhost$ ssh-copy-id username@myIP
    username@myIP password:
    
  3. Now try to login (there will be no password prompt):

    ssh username@myIP
    

Notes: I never edit ssh_config and sshd_config so maybe you can restore them back to the original state unless they already connected.

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.