EDIT: Putting exactly what was done
I need to SSH localhost without password, the usual way of doing it (with public keys) do not work.
user@PC:~$ rm
The correct and safe way of doing it is to copy the keys as has been said here.
In other cases, sshpass
can be handy.
sshpass -p raspberry ssh pi@192.168.0.145
Keep in mind that this is not safe at all. Even though it is not a good idea to use it in secure environments, it can be useful for scripting, automated testing...
this can be combined with
ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no pi@192.168.0.145
to avoid confirmation questions that prevent scripting from happening.
Again, only use this in development systems where different machines share an IP and security is not important.
https://ownyourbits.com/2017/02/22/easy-passwordless-ssh-with-sshh/
Two simple steps:
ssh-keygen -t rsa <Press enter for each line>
ssh-copy-id localhost
Enter password and you're done.
I faced the same issue even after following all the recommendations, but found out that the issue was with gnome-keyring interference.
Solution:
I solved ssh login problem this way.
I generate the key pairs on my server side and then scp back the private key to my windows 10 computer and now I can login without password.
Previously I used key pairs generated by my window 10 laptop and there was no luck at all.
I encountered the same problem when running unit tests on Docker container(golang:1.13-alpine).
After sshd -Dd
and ssh -vv root@localhost
debugging, I found the reason:
User root not allowed because account is locked
So, we should unlock the account by passwd -u
or set a password.
I did following 3 steps to create the password less login
1. ssh-keygen -t rsa
Press enter for each line
2. cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
3. chmod og-wx ~/.ssh/authorized_keys