git-ssh 配置和使用

作者: 高高叔叔 | 来源:发表于2017-05-03 00:48 被阅读426次

现在很多都是和git进行项目管理 但我们用HTTP 协议进行push的时候总是会遇到一些问题比如文件过大之类的。 决定用了SSH 协议。

设置Git的user name和email
$ git config --global user.name "humingx"
 $ git config --global user.email "humingx@yeah.net"
生成密钥
$ ssh-keygen -t rsa -C "humingx@yeah.net"

连续3个回车。如果不需要密码的话。
最后得到了两个文件:id_rsa和id_rsa.pub。

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/zhengmingxiang/.ssh/id_rsa): 
Created directory '/Users/zhengmingxiang/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/zhengmingxiang/.ssh/id_rsa.
Your public key has been saved in /Users/zhengmingxiang/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:GT1GWBv7F7VJ5PfPRSFkSwoAkxHQUVe5fPvnEdlDJgg 13365068888@sina.cn
The key's randomart image is:
+---[RSA 2048]----+
|   .o*Bo.E=.o=.+.|
|     o. ooo== =.+|
|        . Bo.o.*o|
|         + = .+o=|
|        S   o o++|
|             o .=|
|              ..o|
|               .o|
|               .o|
+----[SHA256]-----+
zhengmingxiangdeMacBook-Pro:~ zhengmingxiang$ 

如果不是第一次overwrite选择y

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/zhengmingxiang/.ssh/id_rsa): 
/Users/zhengmingxiang/.ssh/id_rsa already exists.
Overwrite (y/n)? 
添加密钥到ssh-agent
$ ssh-add ~/.ssh/id_rsa

得到结果,这是后面要用到的文件的路径

Identity added: /Users/zhengmingxiang/.ssh/id_rsa (/Users/zhengmingxiang/.ssh/id_rsa)
登陆Github, 添加 ssh

前往路径把id_rsa.pub文件里的内容复制到这里管理密钥的key里面(相信大家可以自己找到添加的位置)。

测试
ssh -T git@github.com

你将会看到:

The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes

选择 yes

Hi godwar10! You've successfully authenticated, but GitHub does not provide shell access.

成功了。现在就可以使用ssh创建新仓库了

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@kd.gdgs.com:zhengmx_test.com/ww.git
git push -u origin master

相关文章

  • git学习记录

    git-ssh 配置和使用

  • GitCommand

    git-ssh 配置和使用 https://segmentfault.com/a/1190000002645623

  • git-ssh 配置和使用

    转自:https://segmentfault.com/a/1190000002645623

  • git-ssh 配置和使用

    https://segmentfault.com/a/1190000002645623 1、设置Git的user ...

  • git-ssh 配置和使用

    现在很多都是和git进行项目管理 但我们用HTTP 协议进行push的时候总是会遇到一些问题比如文件过大之类的...

  • git-ssh 配置和使用

    转载 (原文更详细)https://segmentfault.com/a/1190000002645623 1、设...

  • git-ssh的配置和使用

    1、设置Git的user name和email:(如果只是设置当前仓库就不需要加--global) 2、生成密钥 ...

  • git-ssh配置使用

    1、设置Git的user name和email:(如果是第一次的话) $ git config --global ...

  • 轻松的Git时间

    这里就记录了一些自己常用的Git命令,好记性不如烂笔头~ git-ssh 配置与使用 若执行ssh-add /pa...

  • Git-SSH配置

    2016/07/17 windows用户请在git-shell中使用以下命令 Git是一个版本控制系统 Git中文...

网友评论

    本文标题:git-ssh 配置和使用

    本文链接:https://www.haomeiwen.com/subject/rdahtxtx.html