How to set up an SSH config-file for beginners

前端 未结 2 916
别那么骄傲
别那么骄傲 2020-12-18 16:39

First I am fairly new to SSH.

From this question I have seen the need and benefit of setting up an SSH config file. While I was doing my research I noticed that the

2条回答
  •  生来不讨喜
    2020-12-18 16:41

    By default, your %HOME% will be your %USERPROFILE%

    To create new keys, make sure to add to your environment variables:

    set GH=C:\path\to\git
    set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
    

    That way, you will have all the commands you need, including ssh-keygen, on Windows 10, right from any CMD session (without even opening a git bash session).

    To create a new SSH key, try first to use an SSH key without passphrase, and make sure to create it with the legacy format in a CMD session (not git bash):

    ssh-keygen -m PEM -t rsa -P "" -f %USERPROFILE%\.ssh\myNewKey
    

    'myNewKey': no extension; no '.xxx'.
    (The -m PEM is for producing the legacy format, because not all remote servers are able to understand then new OPENSSH format)

    Then add your %USERPROFILE%\.ssh\config file, to associate your new key to your service (in which you will have registered your %USERPROFILE%\.ssh\myNewKey.pub public key)

    See "Multiple Github Accounts With Git In Windows" for an concrete example, as in:

    ssh-keygen -m PEM -t rsa -P "" -f %USERPROFILE%\.ssh\github_key
    

    Then, in %USERPROFILE%\.ssh\config:

    Host gh
     HostName github.com
     User git
     IdentityFile ~/.ssh/github_key  
    

    That way, you can replace the remote URL of GitHub repository with:

    gh:/
    

提交回复
热议问题