1、生成RSA公钥私钥
ssh-keygen -t rsa -C "aswift@126.com"
目录/.ssh/id_rsa下回生成 私钥:id_rsa 公钥:id_rsa.pub
2、添加id_rsa.pub公钥到gitlab SSH密钥
3、克隆项目到本地
git clone git@xxx:test/testprj.git
Cloning into 'testprj'...
git@xxx's password:
Permission denied, please try again.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
4、总提示需要输入登陆密码
5、添加我们生成的私钥到本地ssh
ssh-add id_rsa
Could not open a connection to your authentication agent.
6、报错:Could not open a connection to your authentication agent.
7、启动ssh-agent
ssh-agent bash
8、再次添加我们生成的私钥到本地ssh
$ ssh-add id_rsa
Identity added: id_rsa (aswift@126.com)
9、再次克隆项目到本地
$ git clone git@xxxx:test/testprj.git
Cloning into 'testprj'...
10、全局设置
git config --global user.name "swift"
git config --global user.email "aswift@126.com"
11、创建新版本库
git clone git@xxxx:test/testprj.git
cd testprj
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
12、已存在的文件夹或 Git 仓库
cd existing_folder
git init
git remote add origin git@xxx:test/testprj.git
git add .
git commit
git push -u origin master