记一次虚拟机Linux中使用Git出现的问题
一、网络连接问题
导入虚拟机后发现不能联网,尝试命令
1 |
|
查了一下原因,是因为这个命令需要在root下才能运行。
于是切换成root
1 |
|
输入密码后进入root,再尝试上面的两条指令。
发现还是不行,原因是需要把虚拟机的网络设置为网桥。VMWare提供了三种工作模式,它们是bridged(桥接模式)、NAT(网络地址转换模式)和host-only(主机模式)。
修改后发现浏览器可以连接百度等外网了。
二、git的配置
1)个人信息配置
配置个人的用户名称和电子邮件地址,这是在你每次提交代码时的说明,知道谁提交了,联系谁
git config –global user.name “caiping”设置用户名
git config –global user.email 12800xxxx@qq.com 设置邮箱
git config –list查看git配置信息
2) github 无密钥登录配置(在git bash下面操作)
授权
ssh-keygen -t rsa -b 4096 -C “xxx@qq.com”
在本地git授权github,有两种方式授权HTTPS或者SSH
这里介绍SSH授权:
首先生成ssh key,出现提示一直回车cat ~/.ssh/id_rsa.pub, 查看公钥,添加至http://github.com
测试是否配置成功
ssh git@github.com
3) 阿里Code无密钥登录配置 http://code.aliyun.com
生成SSH key
id_rsa_code_aliyun是SSH中的私钥,id_rsa_code_aliyun.pub则是SSH中对应的公钥,我们要把公钥的内容发布出去,自己保留私钥就可以了.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23xx@yy:~/.ssh$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/google/.ssh/id_rsa): id_rsa_code_aliyun
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_code_aliyun.
Your public key has been saved in id_rsa_code_aliyun.pub.
The key fingerprint is:
ff:af:52:d0:e8:23:4f:84:40:ae:5e:44:6a:cb:a7:0c your_email@example.com
The key's randomart image is:
+--[ RSA 4096]----+
| .o |
| +. |
| o o. . o |
| o + . + . |
| E + o So . |
| + + ..+ . |
| + +.o |
| o. |
| .oo. |
+-----------------+
google@H:~/.ssh$ ls id_rsa_code_aliyun* -a
id_rsa_code_aliyun id_rsa_code_aliyun.pub添加公钥id_rsa_code_aliyun.pub到阿里云Code
用notepad++ 打开,ctr+a,ctr+c 复制(因为生成的公钥可能含有空格)配置.ssh config文件
可以参考阿里云ssh的README
文件地址 ~/.ssh/config ,如果没有的话 touch config(新建一个config) 即可,然后在里面添加下面的内容1
2
3Host code.aliyun.com
HostName code.aliyun.com
IdentityFIle ~/.ssh/id_rsa_code_aliyun验证连通成功
ssh -T git@code.aliyun.com1
2
3
4
5ssh -T git@code.aliyun.com
* Welcome to aliyun Code *
Hi ${your_email}, you have successfully connected over SSH.
To clone a hosted Git repository, use:
git clone git@localhost/REPOSITORY_NAME.git
如果没有配置config文件,报错如下:
1
2
3
4
5
6ssh -T git@code.aliyun.com
The authenticity of host 'code.aliyun.com (120.55.150.20)' can't be established.
RSA key fingerprint is 69:ab:cb:07:eb:a3:e1:f3:0b:2e:f4:23:b0:c1:c6:9a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'code.aliyun.com,120.55.150.20' (RSA) to the list of known hosts.
Received disconnect from 120.55.150.20: 2: Too many authentication failures