如何为初学者设置SSH配置文件 [英] How to set up an SSH config-file for beginners
问题描述
首先,我是SSH的新手.
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 there is a lot to know on SSH and I also found out that I have been using SSH keys and not the SSH server. I have been using the keys to push my code to my hosted repos.
所以现在我的问题是(我正在使用Windows 10):
So now my questions are(I am using windows 10):
- 我可以不使用openSSH之类的工具来设置SSH配置文件吗?
- 此配置文件存储在我的计算机中的什么位置?
推荐答案
默认情况下,您的%HOME%
将是您的%USERPROFILE%
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%
这样,您将可以从任何CMD会话(甚至不打开git bash
会话)直接获得Windows 10上所需的所有命令,包括ssh-keygen
.
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).
要创建新的SSH密钥,请首先尝试使用不带密码短语的SSH密钥,并确保使用旧格式创建 在CMD会话中(不是git bash):
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
':无扩展名;没有'.xxx
'.
(-m PEM
用于产生旧格式,因为并非所有远程服务器都能够理解新的OPENSSH格式)
'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)
然后添加您的%USERPROFILE%\.ssh\config
文件,以将新密钥与您的服务相关联(您将在其中注册您的%USERPROFILE%\.ssh\myNewKey.pub
公钥)
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)
有关具体示例,请参见"在Windows中具有Git的多个Github帐户",例如:
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
然后,在%USERPROFILE%\.ssh\config
中:
Host gh
HostName github.com
User git
IdentityFile ~/.ssh/github_key
这样,您可以将GitHub存储库的远程URL替换为:
That way, you can replace the remote URL of GitHub repository with:
gh:<yourGitHubUser>/<yourGitHubRepo>
这篇关于如何为初学者设置SSH配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!