Linux – Allow either password or private key SSH authentication

linuxSecurityssh

I set the lines PasswordAuthentication yes and PubkeyAuthentication yes in /etc/ssh/sshd_config. I also disabled root login for security purposes. I can now SSH with a user's password without specifying my private key. However I am now unable to deploy over ssh to my server from a script because I would need to specify the password. Therefore I would like the option to ssh into my server without a password by just specifying the private key. However I am always being asked for the password, even if I pass the private key to the -i option. How can I set this up?

Please note that this is not a passphrase associated with the private key, but rather the password associated with the user. It's the password created with the passwd command.

Best Answer

If the SSH key isn't passphrase locked, the most likely problem is permissions on the destination user's ~/.ssh directory or ~/.ssh/authorized_keys (or ~/.ssh/authorized_keys2) file. I usually set those 600 and 644 respectively, and things work for me.