When I execute the command ssh localhost (in Ubuntu 10.10), it will display the error message "permission denied(public key)." What may be the problem?

Is there any problem in sshd_config file in /etc/ssh? Should PasswordAuthentication be set to no? I have set the PasswordAuthentication to no, but still it gives me the error "permission denied(publickey)."

  • Did you disable password authentication in sshd_config? Why? What you are trying to do with this? – ulidtko Apr 26 '11 at 8:47
  • Can you include the output of /etc/ssh/sshd_config? Use pastebin (pastebin.ubuntu.com) and take out any sensitive information – ldias Apr 27 '20 at 17:59

you need to set file permissions right , try this ..

 $chmod go-w ~/
 $chmod 700 ~/.ssh
 $chmod 600 ~/.ssh/authorized_keys
  • @Volution2111Volution2111:thanks ya.. its worked fine now, I hv set the permissions.. – priyaudupi Apr 27 '11 at 2:57
  • @Statwonk, what? His answer is completely valid, an incorrect permission is going to cause ssh keys to fail automatically, and the ~/.ssh is the default home directory that ssh keys are stored to on almost all *nix distros. – Michael Ryan Soileau Jul 17 '15 at 23:15
  • @MichaelRyanSoileau you're right, I don't remember making this comment, but it clearly looked wrong (removed it). Thanks for raising it to me! – Statwonk Jul 18 '15 at 0:22

Try this:

ssh-copy-id -i ~/.ssh/id_rsa.pub user@host

Or since you are on localhost try copying your ssh key (rsa or dsa) inside the file $HOME/.ssh/authorized_keys.

For key authentication in ssh, you need to authorize your keys on host first AFAIK.

  • hey still it does not work ya.. what is the problem do u kw?? – priyaudupi Apr 26 '11 at 7:26

Make sure you've installed "openssh-server" because it's not installed by default.

sudo apt-get install openssh-server

  • If it was not installed, OP would not get an error message at all, but hang. – Lekensteyn Apr 26 '11 at 8:52
  • @Lekensteyn You would normally think that .. but NO. It does not just hang. – david6 Dec 27 '20 at 10:23

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.