SSH password less setup asking for password

Hello Experts,

when I am trying to connect my target server through sftp after creating ssh password less setup, it is asking for passowrd to connect.

to setup this I followed below process:

-->generated keys by executing the command "ssh-keygen -t rsa"

-->this created my .ssh directory and id_rsa,id_rsa_pub keys

-->after I executed the command "touch authorizedkeys" and gave permissions 600

--> I copied key from my target server into source authorizedkeys file and vice versa.

so now I tried to connect through sftp it is asking for password.

please suggest me, if I am missing anything..

Thanks,
Devi ch

I guess ssh access doesn't work passwordlessly either. Your description of the work flow is not too clear nor detailed; you need to make sure the public key created is appended to the target user's ~/.ssh/authorized_keys file on the target host, and both directory and file have the correct permissions (this is a recommendation, not a requirement).

yes I checked on permissions both directory and files having 755. And public key I appended to authorized_keys too.

source to target it is working, but target to source it is asking for password.

Usually, only one direction is used; on rare occasions only you need the reverse connection.
Did you set up the "target to source" connection the identical way, but source and target mirrored? Please describe the process in full detail - what was done where, what goes where, ...

  • Incorrect permission for .ssh directory and authorized_keys / authorized_keys2 file
  • Corrupt key file, regenerate and copy again.
  • Space,character or line inserted or truncated during appending to existing file. Don�t copy keys manually but do a cat new_keys >> authorized_keys ; For new files copy the file and rename , don�t manually copy paste contents.
  • check the .ssh directory permission
  • try to debug connection

Remember that the permissions have to be locked down at both ends so only the owner at the client end ONLY can read the private key and that the userid on the server (target) ONLY can read/write the public key. SSH and other tools that use these keys will check that they are not vulnerable to someone else editing them. You should also check that the directory permissions for .ssh are read/write/execute for the owner ONLY.

Do not allow any other access to these files. The blanket chmod 777 ....... will make prevent you using them. Try chmod 600 ~/.ssh/* and chmod 700 ~/.ssh on both the client and the server.

If it's not any of the above, when you generated the keys I'm wondering if your provided a passphrase. This would require you to enter the passphrase every time to use the keys, so you can't automate it.

It is best practice to have a passphrase for interactive use of the keys. If you wish, you can have multiple keys defined and use the one without a passphrase for automated processing using the -i flag.

I hope that this helps,
Robin

I have run across this time and again and it always takes me a while to remember why. Openssh was specifically written to disallow connection if the permissions of .ssh are too open. see Ubuntu's writeup on this

Also, try setting your home directory permissions to 700.

Also, instead of copying your ssh key around and possible making paste mistakes, just use the following command to install your key on a remote host:

ssh-copy-id

Hi,

After all your suggestions, I tried to make new setup as I have deleted old keys and .ssh directory.

Now to avoid manual pasting of keys, I can use cat keys >> authorizedkeys as suggested. But I need to paste the keys of source server into target server authorized keys file. and vice versa. To copy like that what command I can use?? while I am using the above command the keys of source server pasting into same server authorized keys.

please suggest.

---------- Post updated at 05:33 AM ---------- Previous update was at 03:00 AM ----------

Even I setup newly, not working properly asking for password again. I checked on permissions too. gave 700 for ssh directory and authorized keys. for both source and target servers. even in one way its not working. please suggest me what I am missing.

HI

put 600 for authorized keys

always use ssh-copy-id command