好的,我已经在网上读了很多帖子,没有一个是真正明确的,或者至少对我的技术水平的人来说。我在windows上设置了Ubuntu子系统,我正在尝试设置我的github密钥,这样我就不必每次推送都登录。
如果你有简单的步骤,请忽略下面的其余部分,只是想确保我提供了与我在下面尝试的内容相同的信息。
我尝试了这种方法,但仍然无法使其工作-在Windows上启动Git Bash时运行SSH代理
以下是我采取的全部步骤
1) 我运行了$ssh-keygen-t rsa-b 4096-C“my@email.com“代码>
在提示键添加到默认位置时按回车键希望是/. ssh
(在linux端)位于此处的窗口上:C:\用户\MyUserName\AppData\本地\Packages\CanonicalGroupLimited。UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\MyUserName\. ssh
在/中此步骤之后添加的文件。ssh
/.ssh
id_rsa
id_rsa.pub
2) 接下来我修改了我的。带nano的bashrc
$ nano ~/.bashrc
这打开了C:\用户\MyUserName\AppData\本地\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\MyUserName\. bashrc
我在现有代码的末尾添加了以下代码段。bashrc公司
# Set up ssh-agent
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initializing new SSH agent..."
touch $SSH_ENV
chmod 600 "${SSH_ENV}"
/usr/bin/ssh-agent | sed 's/^echo/#echo/' >> "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
kill -0 $SSH_AGENT_PID 2>/dev/null || {
start_agent
}
else
start_agent
fi
3) 我运行了源代码。bashrc
4) 创建了配置文件。ssh/config
5) 在配置中,这是我所拥有的和我认为可能出错的地方。
这是上面引用的原始帖子的片段
Host github.com-<YOUR_GITHUB_USERNAME>
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_work_gmail # path to your private key
AddKeysToAgent yes
Host csexperimental.abc.com
IdentityFile ~/.ssh/id_work_gmail # path to your private key
AddKeysToAgent yes
<More hosts and github configs can be added in similar manner mentioned above>
这是我的
Host github.com-MyGithubUsername
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
AddKeysToAgent yes
6) 然后,我通过运行ssh add向代理添加了密钥。ssh/id\u rsa
我运行了$ssh github。com MyGithubUsername检查一切是否正常并返回
The authenticity of host 'github.com (192.XX.XXX.XXX)' can't be established.
RSA key fingerprint is SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
Are you sure you want to continue connecting (yes/no)?
我输入yes
并返回
Warning: Permanently added 'github.com,192.XX.XXX.XXX' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi MyUserName! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
在此之后尝试推动提交,但仍要求我登录
我也看到了这篇文章,尽了最大努力,但也没有成功,所以我从头开始,尝试了上面的方法
如有任何帮助,我们将不胜感激:/
如果您使用的是SSHURL,这些步骤是可以的:
cd /path/to/my/repo
git remote -v
如果以https开头:
git remote set-url origin github.com-MyGithubUsername:<mylogin>/<myrepo>
请注意,只有在设置私钥时添加了密码短语时,才需要SSH代理。