I tried everything mentioned in this solution Why am I still getting a password prompt with ssh with public key authentication?, but still getting prompt for password.

My local log:

ssh -vvv srvFlink@remoteHost

debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/srvFlink/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/srvFlink/.ssh/id_dsa
debug3: no such identity: /home/srvFlink/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/srvFlink/.ssh/id_ecdsa
debug3: no such identity: /home/srvFlink/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/srvFlink/.ssh/id_ed25519
debug3: no such identity: /home/srvFlink/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
srvFlink@remoteHost's password:

Remote machine file permission:

drwx------.  2 srvFlink srvFlink   58 Aug 18 04:46 .ssh

-rw-------. 1 srvFlink srvFlink 1679 Aug 18 04:41 id_rsa
-rw-r--r--. 1 srvFlink srvFlink  406 Aug 18 04:41 id_rsa.pub
-rw-rw-r--. 1 srvFlink srvFlink  406 Aug 18 04:45 authorized_keys
drwx------. 2 srvFlink srvFlink   58 Aug 18 04:46 .
drwx------. 4 srvFlink srvFlink 4096 Aug 18 05:14 ..

In /etc/selinux/config file I have.

SELINUX=permissive
SELINUXTYPE=targeted

Content of id_rsa.pub of my local machine is there in the Remote machine ~/.ssh/authorized_keys

Content of /etc/ssh/sshd_config is same in both of the machine.

What might be the issue?

EDIT

Looks like file permission issue:

$ journalctl _COMM=sshd
Aug 18 06:54:53 localhost sshd[8891]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
Aug 18 06:54:53 localhost sshd[8891]: Authentication refused: bad ownership or modes for file /home/srvFlink/.ssh/authorized_keys
Aug 18 06:54:56 localhost sshd[8891]: Connection closed by remotehost [preauth]
  • private key should be located on local host not on remote host. From your post is unclear whether you have this file on local host. – user1700494 Aug 18 '16 at 10:35
  • private key is there both in local and as well as in remote. – Zeeshan Aug 18 '16 at 10:38
  • 1
    Then you may search /var/log/authlog on remote side to find out why the server rejected your key. Or post this log there. – user1700494 Aug 18 '16 at 10:40
up vote 4 down vote accepted
-rw-rw-r--. 1 srvFlink srvFlink  406 Aug 18 04:45 authorized_keys

should be

-rw-r--r--. 1 srvFlink srvFlink  406 Aug 18 04:45 authorized_keys

as noted in the post you linked in your question, where the accepted answer reads in part "Your home directory ~, your ~/.ssh directory and the ~/.ssh/authorized_keys file on the remote machine must be writable only by you"

You also don't post the permissions on your home directory in the question; ensure that those are also not group- or other-writable.

I had the exact same problem on two servers: a Linux running Debian stretch and on a NAS (Synology DS715)

it turned out that in both cases, the home directory permissions on the server were wrong

the auth.log on the server was very helpful

Authentication refused: bad ownership or modes for directory /home/cyril

on the Linux, it had the write/group bit on (drwxrwxr--x), so I had to remove at least the write on group (chmod g-w ~/) and then it worked

on the Synology, for whatever reason, there was a sticky bit

drwx--x--x+ 4 toto users 4096 Jan 6 12:11 /var/services/homes/toto

I had to change it with

chmod -t ~/

and I could then connect without a password

The debuglog clearly shows that your ssh client only tries id_rsa, id_dsa, id_ecdsa and id_ed25519 files, not id_rsa.pub.

  • 2
    If client provides public key instead of private one it will not work anyway. – user1700494 Aug 18 '16 at 10:42
  • then check the log of sshd. – Ipor Sircer Aug 18 '16 at 10:49

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.