How to ssh to localhost without password?

后端 未结 12 724
无人及你
无人及你 2020-12-07 13:05

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         


        
相关标签:
12条回答
  • 2020-12-07 13:28

    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/

    0 讨论(0)
  • 2020-12-07 13:33

    Two simple steps:

    ssh-keygen -t rsa <Press enter for each line>
    ssh-copy-id localhost
    

    Enter password and you're done.

    0 讨论(0)
  • 2020-12-07 13:35

    I faced the same issue even after following all the recommendations, but found out that the issue was with gnome-keyring interference.

    Solution:

    1. Go Search , look for “Startup Applications”
    2. If you see “SSH Key Agent”, uncheck the box
    3. Reboot the machine and connect to localhost.
    0 讨论(0)
  • 2020-12-07 13:35

    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.

    0 讨论(0)
  • 2020-12-07 13:38

    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.

    0 讨论(0)
  • 2020-12-07 13:45

    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 
    
    0 讨论(0)
提交回复
热议问题