栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

windows11 git命令访问github

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

windows11 git命令访问github

注意事项:
1)以下所有命令都是在git bash中执行;
2)由于默认.ssh目录路径中包含中文,执行ssh-keygen时不使用默认路径,指定另外的密钥文件路径,比如:/c/.ssh/id_rsa ; 
3)需要提前在c盘生成.ssh目录,并生成一个空白的/c/.ssh/id_rsa文件;
4)"xxxxxx@xxx.com"需要修改为你个人email;

首先执行ssh看看域名解析有没有问题,如果有问题,如下:
$ ssh -T git@github.com
ssh: Could not resolve hostname github.com: No address associated with hostname

这时手动设置dns ip地址为8.8.8.8及8.8.4.4
参考下面的文章:
https://zhongguo.eskere.club/%E5%A6%82%E4%BD%95%E5%9C%A8-windows-11-%E4%B8%AD%E6%9B%B4%E6%94%B9-dns-%E8%AE%BE%E7%BD%AE/2021-10-13/

设置完后,再次执行ssh,提示permission denied,如下:
$ ssh -T git@github.com
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
git@github.com: Permission denied (publickey).


然后执行ssh-keygen并指定key文件为/c/.ssh/id_rsa,如下:
$ ssh-keygen -t rsa -b 4096 -C "xxxxxx@xxx.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxxx/.ssh/id_rsa): /c/.ssh/id_rsa
/c/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/.ssh/id_rsa
Your public key has been saved in /c/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:RKP9snwKcQ+nqBnS+I6tMt8LOXcUXXrnZd51bN6HeKk xxxxxx@xxx.com
The key's randomart image is:
+---[RSA 4096]----+
|        o .      |
|       = +     . |
|      o = . . o =|
|       o o o = *+|
|      o S o o = =|
|   + . = B   o  .|
|  * + + + o E    |
|o  X = . o       |
| ++oO.  .        |
+----[SHA256]-----+

然后,拷贝id_rsa.pub文件内容并粘贴到github profile上去:
Github profile -> Settings -> SSH and GPG Keys -> Add new SSH key

接着执行ssh-add,出现如下提示:
$ ssh-add /c/.ssh/id_rsa
Could not open a connection to your authentication agent.

然后执行:
$ eval $(ssh-agent) 或者 eval $(ssh-agent -s)
Agent pid 1118

OK后,接着又执行ssh-add,这次OK了:
$ ssh-add /c/.ssh/id_rsa
Identity added: /c/.ssh/id_rsa (xxxxxx@xxx.com)

继续执行:
$ ssh -T git@github.com
Hi xxxxxx! You've successfully authenticated, but GitHub does not provide shell access.

对了,如果没有配置.gitconfig的话,要配置:
git config --global user.name "xxxxxx"
git config --global user.email "xxxxxx@xxx.com"

然后就可以git clone啦。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/963167.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号