1.You won't be able to pull or push project code via SSH until you add an SSH key to your profile(你不能拉或推项目代码通过SSH直到你SSH密钥添加到您的配置文件)
解决步骤:
bogon:~ ldci$ cd .ssh
bogon:.ssh ldci$ ls\
> 出现这个标记时回车就行
bogon:.ssh ldci$ ls -a
. .. known_hosts //以上是查看ssh文件是否存
bogon:.ssh ldci$ ssh-keygen -t rsa -C "duxiaolei@duia.com" //创建ssh(邮箱改成自己公司提供的git的邮箱)
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/ldci/.ssh/id_rsa): //回车回车回车
Enter passphrase (empty for no passphrase): (回车不需要设置密码)
Enter same passphrase again: (回车没有设置密码)
Your identification has been saved in /Users/ldci/.ssh/id_rsa.
Your public key has been saved in /Users/ldci/.ssh/id_rsa.pub.
The key fingerprint is:
7a:28:6b:bd:ef:f0:1b:5e:a0:71:0a:b2:b7:b5:0e:7d duxiaolei@duia.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| |
| . . . S |
| o o B . |
| . +.O E . |
| ..*.B o |
| .o.++*. |
+-----------------+
bogon:.ssh ldci$ ls -a
. .. id_rsa id_rsa.pub known_hosts //成功生成ssh
bogon:.ssh ldci$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4j68iKedLGUqrtTCZA0qBYw5lEUQz7Yhhh/JJL0JyznQ+ZqKoaY2CaPwMVYJduJYCiRWcqeuStfmsHcz4IDlucB4wqapQn/E6pJh+j30bVy60BI5EVX0rX42s5oiaHhA/D2joJDuJS4CS2FupobzYS7DtAUTxHPrP8vAo0HInw74Xk0KYoTKf3zrDpt9JA/bTvWjnrKFtsn+yQLS2W40uMb0EomFVsyIrMIhO8L+J6lWMxiR1OjsxIzrpSIFICa9LbfXAYT/28zDNodulpLuyPQ0rstEi3YI9VQp9QztLNlc1JNE8b70E7uhA+OUqmHuewtzBp6MLvBHQ78oupR5b duxiaolei@duia.com
/*到这一步已经获得了SSH秘钥了可以添加到git上了*/
bogon:.ssh ldci$
使用账号duxiaolei 密码:Duia_duxiaolei 登录git.duia.org.cn
将上面生成的ssh 添加进去:
/// 下面的貌似不用输入也可以成功拉取代码了
添加用户名和邮箱
CC:kuaijibang ldci$ cd ~/.ssh
CC:.ssh ldci$ ls
id_rsa id_rsa.pub known_hosts
CC:.ssh ldci$ git config --global user.name "duxiaolei"
CC:.ssh ldci$ git config --global user.email "duxiaolei@duia.com"
CC:.ssh ldci$ git config --list
user.name=duxiaolei
user.email=duxiaolei@duia.com
CC:.ssh ldci$ cd /Users/ldci/Desktop/kuaijibang
CC:kuaijibang ldci$ git clone git@git.duia.org.cn:zhoumingxi/kuaijibang.git
user.email=duxiaolei@duia.com
(以上是实际操作截图)
教程:
cd ~/.ssh
# 生成rsa密钥,密钥秘钥:123456
ssh-keygen -t rsa -C "xxx@gmail.com”
# 将密钥文件复制到剪贴板
pbcopy < ~/.ssh/myname_rsakey.pub
# 进入github,设置ssh密钥
# 1. Edit Profile
# 2. SSH Keys
# 3. Add SSH Key
# 4. 将刚刚复制的Key粘贴,然后提交
# 添加rsa密钥
ssh-add myname_rsakey
# 测试github连接
ssh -T git@github.com
# 关联项目
cd 项目文件夹/
# 为当前文件夹初始化git
git init
# 添加远程服务器
git remote add origin git@github.com:liufan321/HelloWorldDemo.git
# 从服务器拉项目
git pull -u origin master
# 将项目内容推送到服务器
git push -u origin master