SSH Key - Still asking for password and passphrase

后端 未结 30 1367
孤街浪徒
孤街浪徒 2020-11-27 08:35

I\'ve been somewhat \'putting up\' with Github always asking for my username and password when I clone a repository. I want to bypass this step because it is an annoyance w

30条回答
  •  攒了一身酷
    2020-11-27 09:22

    I'd like to add an answer for those who may still need to enter the password because they have set IdentitiesOnly as yes. This may cause by multiple keys and the identity file, being keys for git or server.

    After I have generated the key and copied it to the server:

    ssh-keygen
    ssh-copy-id -i ~/.ssh/12gpu_server.pub lerner@192.168.20.160
    

    I found it didn't work.

    Then I went to check the ~/.ssh/config file, I saw this at the bottom:

    Host *
    IdentitiesOnly yes
    

    Then I add this above:

    Host 12gpu
    HostName 192.168.20.160
    User lerner
    IdentityFile ~/.ssh/12gpu_server
    

    I can just log in by entering ssh 12gpu.

    Then you can add multiple ssh keys using your favorite names, and you only need to add the settings like the above four lines to the config file.

    Host is the name you'd like to enter when you connect to the server later; the HostName is the server's ip or domain like github.com; User is the user name you log in the server like the user name or git for github or gitlab; and the IdentityFile is the file where you store the key you have generated.

提交回复
热议问题