0
votes

I am using ssh-keygen and giving no pass phrase then key-fingerprint is successfully generated and shown.
Then I'm giving ssh-copy-id user@localhost then its prompting for my user's password after providing it states Number of key(s) added : 1.
Now if I'm doing ssh localhost its again prompting for password.
also If I do ssh user@localhost it asks for password.

PS : I have used : ssh-add and also sudo ufw allow 22 nothing seems to work fine everytime I do ssh localhost I have been prompted with password.

[EDIT]

ssh -v localhost
shows

debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA b2:58:a9:da:84:3f:43:1c:86:51:ba:cd:b7:88:a3:74
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /home/harsh/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering DSA public key: /home/harsh/.ssh/id_dsa
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: /home/harsh/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/harsh/.ssh/id_ecdsa
debug1: Trying private key: /home/harsh/.ssh/id_ed25519
debug1: Next authentication method: password
harsh@localhost's password:

3
Is your public key in the .ssh/authorized_keys file?knittl
You can run ssh -v user@localhost and inspect debug output to see what private keys are tried by ssh client, and what are the outcomes.mephi42
@knittl yes public key is thereHarsh Vardhan Ladha
Trying Private Key .ssh/id_ecdsa and .ssh/id_ed25519 and then it shows Next authentication method : passwordHarsh Vardhan Ladha

3 Answers

1
votes

I would check these:

  • make sure that the remote .ssh directory and authorized_keys file have proper permissions

    • both should be owned by you
    • permissions should be 0700 (rwx:---:---) on $HOME/.ssh and
    • 0600 (rw-:---:---) on $HOME/.ssh/authorized_keys
  • verify that the ssh daemon allows for key auth, i.e. for openssh server there should be this line in its config:

    • PubkeyAuthentication yes

Then re-run your ssh command with debugging output enabled

  • ssh -v yourhost

It will show you which authentication methods it is going to try, i.e.

debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Next authentication method: publickey

Good luck! :)

0
votes

I managed to overcome this problem by simply re-installing the ssh on my ubuntu machine.

The problem was because ssh wasn't installed properly upon OS installation.

0
votes

I had the same problem in the setup where the /home directory was mounted via NFS (Network File System). Bellow command did the job.

[root@localhost]# setsebool -P use_nfs_home_dirs=true