@@ -328,4 +328,133 @@ $ git pull
328328
329329
330330- [ Git - 储藏与清理] ( https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%82%A8%E8%97%8F%E4%B8%8E%E6%B8%85%E7%90%86 )
331- - [ git stash详解 - stone_yw的博客 - CSDN博客] ( https://blog.csdn.net/stone_yw/article/details/80795669 )
331+ - [ git stash详解 - stone_yw的博客 - CSDN博客] ( https://blog.csdn.net/stone_yw/article/details/80795669 )
332+
333+
334+
335+ ## 3. SSH 连接配置
336+
337+ ### 1. 生成密钥对
338+
339+ 大多数 Git 服务器都会选择使用 SSH 公钥来进行授权。系统中的每个用户都必须提供一个公钥用于授权,没有的话就要生成一个。生成公钥的过程在所有操作系统上都差不多。首先你要确认一下本机是否已经有一个公钥。
340+
341+ SSH 公钥默认储存在账户的主目录下的 ~ /.ssh 目录。进去看看:
342+
343+ ``` shell
344+ $ cd ~ /.ssh
345+ $ ls
346+ authorized_keys2 id_dsa known_hosts config id_dsa.pub
347+ ```
348+
349+ 看一下有没有id_rsa和id_rsa.pub(或者是id_dsa和id_dsa.pub之类成对的文件),有 .pub 后缀的文件就是公钥,另一个文件则是密钥。
350+
351+ 假如没有这些文件,甚至连 .ssh 目录都没有,可以用 ssh-keygen 来创建。该程序在 Linux/Mac 系统上由 SSH 包提供,而在 Windows 上则包含在 MSysGit 包里:
352+
353+ ``` shell
354+ $ ssh-keygen -t rsa -C " your_email@youremail.com"
355+
356+ Creates a new ssh key using the provided email # Generating public/private rsa key pair.
357+
358+ Enter file in which to save the key (/home/you/.ssh/id_rsa):
359+ ```
360+
361+ 直接按Enter就行。然后,会提示你输入密码,如下(建议输一个,安全一点,当然不输也行,应该不会有人闲的无聊冒充你去修改你的代码):
362+
363+ ``` shell
364+ Enter same passphrase again: [Type passphrase again]
365+ ```
366+
367+ 完了之后,大概是这样:
368+
369+ ``` shell
370+ Your public key has been saved in /home/you/.ssh/id_rsa.pub.
371+ The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@youremail.com
372+ ```
373+
374+ 到此为止,你本地的密钥对就生成了。
375+
376+
377+
378+ ### 2. 添加公钥到你的远程仓库(github)
379+
380+ 1 . 查看你生成的公钥:
381+
382+ ```
383+ $ cat ~/.ssh/id_rsa.pub
384+
385+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0X6L1zLL4VHuvGb8aJH3ippTozmReSUzgntvk434aJ/v7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8vR3c8E7CjZN733f5AL8uEYJA+YZevY5UCvEg+umT7PHghKYaJwaCxV7sjYP7Z6V79OMCEAGDNXC26IBMdMgOluQjp6o6j2KAdtRBdCDS/QIU5THQDxJ9lBXjk1fiq9tITo/aXBvjZeD+gH/Apkh/0GbO8VQLiYYmNfqqAHHeXdltORn8N7C9lOa/UW3KM7QdXo6J0GFlBVQeTE/IGqhMS5PMln3 admin@admin-PC
386+ ```
387+
388+ 2 . 登陆你的 GitHub 帐户。点击你的头像,然后 ` Settings -> 左栏点击 SSH and GPG keys -> 点击 New SSH key `
389+
390+ 3 . 然后你复制上面的公钥内容,粘贴进“Key”文本域内。 title域,自己随便起个名字。
391+
392+ 4 . 点击 Add key。
393+
394+ 完成以后,验证下这个key是不是正常工作:
395+
396+ ``` shell
397+ $ ssh -T git@github.com
398+
399+ Attempts to ssh to github
400+ ```
401+
402+ 如果,看到:
403+
404+ ```
405+ Hi xxx! You've successfully authenticated, but GitHub does not # provide shell access.
406+ ```
407+
408+ 恭喜你,你的设置已经成功了。
409+
410+ ### 3. 修改git的remote url
411+
412+ 使用命令 git remote -v 查看你当前的 remote url
413+
414+ ``` shell
415+ $ git remote -v
416+ origin https://github.com/someaccount/someproject.git (fetch)
417+ origin https://github.com/someaccount/someproject.git (push)
418+ ```
419+
420+ 如果是以上的结果那么说明此项目是使用https协议进行访问的(如果地址是git开头则表示是git协议)
421+
422+ 你可以登陆你的github,就像本文开头的图例,你在上面可以看到你的ssh协议相应的url,类似:
423+
424+ ![ img] ( assets/1160195-20170512120555144-795931549.png )
425+
426+ 复制此ssh链接,然后使用命令 git remote set-url 来调整你的url。
427+
428+ ``` shell
429+ $ git remote set-url origin git@github.com:someaccount/someproject.git
430+ ```
431+
432+ 然后你可以再用命令 git remote -v 查看一下,url是否已经变成了ssh地址。
433+
434+ 然后你就可以愉快的使用 git fetch, git pull , git push,再也不用输入烦人的密码了
435+
436+
437+
438+
439+
440+ ### 4. 常见问题
441+
442+ - [ Git 提交大文件提示 fatal: The remote end hung up unexpectedly - WNFK - 博客园] ( https://www.cnblogs.com/hanxianlong/p/3464224.html )
443+
444+
445+
446+ ## 4. Git 记住密码
447+
448+ - [ Git Pull 避免用户名和密码方法 - 王信平 - 博客园] ( https://www.cnblogs.com/wangshuo1/p/5531200.html )
449+
450+
451+
452+ ## 5. Git FTP 使用
453+
454+ 利用Git版本管理将只修改过的文件上传到FTP服务器 支持SFTP协议 - 吕滔博客
455+ https://lvtao.net/tool/gitftp.html
456+
457+
458+
459+ ## 6. Git 删除文件如何提交
460+
0 commit comments