Git是分布式的代码管理工具,远程的代码管理是基于SSH的,所以要使用远程的Git则需要SSH的配置。
以阿里云code在windows生成为例,Git的SSH配置如下:
一、设置Git的user name和email:
$ git config --global user.name "bobo" $ git config --global user.email "bobo@aliyun.com"
二、生成SSH密钥过程:
1.查看是否已经有了ssh密钥,存放目录 C:\Users\Administrator\.ssh ,如果没有密钥则不会有此文件夹,有则备份删除。
2.生存密钥:
$ ssh-keygen -t rsa -C "bobo@aliyun.com"
按3个回车,密码为空。
Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): Created directory '/c/Users/Administrator/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa. Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub. The key fingerprint is: SHA256:MFbe+pKB/s1Z/lM4km++XfE1NfA606+0KYftDJRzf7I bobo@aliyun.com The key's randomart image is: +---[RSA 2048]----+ | . . | | o . o | | + . . o.| | . + . .o o| | . S +=.=.| | . + .oo=.B| | . o . o=oo*| | . + +o+*Bo| | . + .BEo.| +----[SHA256]-----+
结束后在C:\Users\Administrator\.ssh 会生成两个文件:id_rsa和id_rsa.pub
三.在阿里云code上的 个人资料 》SSH 密钥 》增加SSH密钥,这要添加的是“id_rsa.pub”文件里面的公钥。
四.测试:ssh git@code.aliyun.com
**** Welcome to aliyun Code **** Hi tech, you have successfully connected over SSH. To clone a hosted Git repository, use: git clone git@localhost/REPOSITORY_NAME.git Connection to code.aliyun.com closed.
输出以上内容则成功!