好吧,我在网上读了很多帖子,没有一个是非常明确的,或者至少对我的技术水平的人来说。我在windows上设置了Ubuntu子系统,我正在尝试设置github密钥,这样我就不必每次推送都登录。
我试过这个方法,但还是不能奏效
Running SSH Agent when starting Git Bash on Windows
1)
我跑了
$ ssh-keygen -t rsa -b 4096 -C "my@email.com"
在提示时按enter键将键添加到默认位置
/.ssh
(在linux端)
在此处的窗口上:
C:\Users\MyUserName\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\MyUserName\.ssh
/.ssh文件
/.ssh
id_rsa
id_rsa.pub
$ nano ~/.bashrc
这个打开了
C:\Users\MyUserName\AppData\Local\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)
我跑了
source ~/.bashrc
4)
已创建配置文件
$ touch ~/.ssh/config
在配置中,这是我所拥有的和我认为我可能出错的地方。
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_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.
在此之后尝试推送提交,但仍要求我登录
this post
我尽了我最大的努力,但也没有成功,所以我从零开始尝试上面的方法
任何帮助都将不胜感激:/