How to ssh to localhost without password?

后端 未结 12 725
无人及你
无人及你 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:49

    Do the following steps

    ssh-keygen -t rsa -C "your_email@example.com"
    # Creates a new ssh key, using the provided email as a label
    # Generating public/private rsa key pair.
    

    Use the default file and empty passphrase (Simply press enter in the next 2 steps)

    # start the ssh-agent in the background
    eval "$(ssh-agent -s)"
    # Agent pid 59566
    ssh-add 
    

    Copy the contents of ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys

    Ensure following are the permissions

     ls -l .ssh/
     total 20
    -rw-r--r--. 1 swati swati  399 May  5 14:53 authorized_keys
    -rw-r--r--. 1 swati swati  761 Jan 12 15:59 config
    -rw-------. 1 swati swati 1671 Jan 12 15:44 id_rsa
    -rw-r--r--. 1 swati swati  399 Jan 12 15:44 id_rsa.pub
    -rw-r--r--. 1 swati swati  410 Jan 12 15:46 known_hosts 
    

    Also, ensure the permissions for .ssh directory are. This is also important

    drwx------.   2 swati swati    4096 May  5 14:56 .ssh
    
    0 讨论(0)
  • 2020-12-07 13:49

    as the accepted answer do, if you encount a problem of

        Agent admitted failure to sign using the key.
    

    you need to

        ssh-add
    
    0 讨论(0)
  • 2020-12-07 13:50

    Have discovered the problem.

    Running the server with debuging:

    $sshd -Dd
    

    I found it was not able to read the auth_key

    $chmod 750 $HOME
    

    Fixed it.

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

    I fixed my problem setting the AllowUsers on sshd_config file.

    Running the server with debuging:

    $sshd -Dd

    I found it was not allowed the my user

    $sudo vi /etc/ssh/sshd_config

    Add a row with after #Authentication:

    AllowUsers myUser

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

    Another possible answer: the authorized_keys file may exist and be readable. But if it is group- or world-writable, it will still prompt for the password. The answer to THAT problem is

    chmod og-wx ~/.ssh/authorized_keys
    
    0 讨论(0)
  • 2020-12-07 13:53

    On Centos 7

    SOLUTION

    1 create rsa key
    2 vim /etc/ssh/ssh_config
    3
    #   IdentityFile ~/.ssh/identity
    uncoment this line > IdentityFile ~/.ssh/id_rsa
    #   IdentityFile ~/.ssh/id_dsa
    #   IdentityFile ~/.ssh/id_ecdsa
    

    Note *I did this after copying the key and some of the other answers before this one. But I am pretty sure this is all you have to do but if not I would append the rsa key to authorized_keys and also run the

    ssh-copy-id to username@localhost

    0 讨论(0)
提交回复
热议问题