当前位置:首页 » 《关注互联网》 » 正文

用SSH来连接Github_CHNMSCS

6 人参与  2021年08月17日 10:03  分类 : 《关注互联网》  评论

点击全文阅读


如果用SSH方法来git clone github repo的话,就得通过以下步骤来做。
博主是以Macbook为例的,如果你是用windows或者linux的,就自己查查怎么安装吧!

  1. 检查本地电脑里有没有SSH keys
    [1] 打开Terminal
    [2] 输入 ls -al ~/.ssh这个命令来检查是否已经有SSH keys
    一般默认情况下的 SSH key 的格式如下:
    (1)id_rsa.pub
    (2)id_ecdsa.pub
    (3)id_ed25519.pub
    如果发现都没 SSH key, 那么就得创建一个新的 SSH key
  2. 创建一个新的SSH key
    [1] 打开 Terminal
    [2] 输入这个命令
$ ssh-keygen -t ed25519 -C "your_email@example.com"

提示:
如果你的苹果电脑系统用的legacy system, 这是不支持 Ed25519的,那么就得使用下面的命令:

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

输入完上面的任何一个命令之后,就会看到这个结果:

> Generating public/private rsa key pair.

紧接着看到另外一个结果:

> Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

这是默认的存key的地址,直接按’enter’就行了

然后就会看到下面的结果:

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

输入完之后,就看到你的identification和public key存在的地方,你的key fingerprint也可以知道,和你的key’s randomart image也可以看到

  1. 将你的SSH key 加入到ssh-agent
    [1] 在后台开始ssh-agent,命令如下:
$ eval "$(ssh-agent -s)"
> Agent pid 59566

提示:这个Agent pid有可能会跟你的不一样。

[2] 如果你的macOS Sierra 10.12.2 or later,you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.
(a) First, check to see if your ~/.ssh/config file exists in the default location.

$ open ~/.ssh/config
> The file /Users/you/.ssh/config does not exist.

(b) 如果文件不存在,就得创建一个新的文件

$ vim ~/.ssh/config

( C ) Open your ~/.ssh/config file, then modify the file to contain the following lines. If your SSH key file has a different name or path than the example code, modify the filename or path to match your current setup. 粘贴下面的代码

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

[3] Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file. 输入下面的命令

$ ssh-add -K ~/.ssh/id_rsa
  1. 添加新的SSH key
    [1] 在添加ssh key之前,先检查,是否已经在本地电脑里有ssh key了
ls -al ~/.ssh

[2] 已经有了ssh key了,就Copy the SSH public key to your clipboard.
If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don’t add any newlines or whitespace.

$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

[3] 去到 Github -> setting -> SSH and GPG keys -> New SSH key
请添加图片描述
[4] 将刚刚已经复制好的ssh key,粘贴到 key区域里,不能添加或者减少任何的字符,包括空格
请添加图片描述
[5] 点击 Add SSH key按钮

  1. 测试你的SSH Connection
    进入到你任何一个repo,尝试一下git push,有可能你会碰到无法git push, 那么你就得用下面的命令来做git push
git push -f origin main

这样以后就可以直接

git push origin main

希望这篇博客,能给你带来帮助。
既然都看到这了,就点赞关注留言一下呗,你的支持是对博主最大的鼓励 ^ ^


点击全文阅读


本文链接:http://zhangshiyu.com/post/25551.html

就得  命令  输入  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • 幽思燃烬忘川路:全书+后续+结局(叶墨谨迟少瑜)_(幽思燃烬忘川路:全书+后续+结局)列表_笔趣阁(叶墨谨迟少瑜)
  • 请别说爱我:全书+后续+结局:全书+后续+结局(宋微夏薄以宸)列表_请别说爱我:全书+后续+结局(宋微夏薄以宸)请别说爱我:全书+后续+结局:全书+后续+结局在线
  • 爱如死水缠绵绵:全书+后续+结局(沈知意傅司寒)_(爱如死水缠绵绵:全书+后续+结局)沈知意傅司寒列表_笔趣阁(沈知意傅司寒)
  • 「鸠占鹊巢的养女逼我女儿退学后,我怒了」小说节选推荐_兰兰小玲阴晴不定全章节免费阅读
  • 他站在回忆尽头:结局+番外实力派(乔若兮沈辞安)
  • 莫用爱囚我傅寒深:+后续_莫用爱囚我傅寒深:+后续
  • [真千金放弃豪门99次,全家悔疯了]小说章节分享_妹妹周婉婉老公全角色番外合集包
  • 迟笙的云间有座相思城:结局+番外精选作品之一迟笙陆景琛裴清浅全书在线
  • 水自无情舟渡人:结局+番外倾心编著列表_水自无情舟渡人:结局+番外倾心编著(穆婉季铭)
  • 我给第三十八任老公过喜:结局+番外笔趣阁(宋青青聂子远)_我给第三十八任老公过喜:结局+番外笔趣阁
  • 且听风吟,君已无音完结_邬砚廷杜晓依灵契族反转剧情试读片段
  • (番外)+(全书)我给第三十八任老公过喜:结局+番外(宋青青聂子远)_我给第三十八任老公过喜:结局+番外免费_笔趣阁(宋青青聂子远)

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1