Mac下如何配置OSChina SSH公钥及配置SourceTree
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mac下如何配置OSChina SSH公钥及配置SourceTree相关的知识,希望对你有一定的参考价值。
利用OSChina提供的免费git空间,可以避免自己配置git服务器的麻烦,同时还能解决SVN不能本地提交的问题
1.在终端下生成SSHKey,有时输入第1遍没有反应,需要运行2遍
ssh-keygen -t rsa -C “你的邮箱"
出现提示:
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/你的Mac用户名/.ssh/id_rsa):
2.直接回车,保存密钥对保存到默认位置/Users/你的Mac用户名/.ssh/id_rsa
出现提示:
Created directory ‘/Users/你的Mac用户名/.ssh‘.
Enter passphrase (empty for no passphrase):
3.输入密码密钥对的密码,一般不设置,直接回车,再次回车
出现类似于这样的提示:
Your identification has been saved in /Users/你的Mac用户名/.ssh/id_rsa.
Your public key has been saved in /Users/你的Mac用户名/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:+4xdhIVKajdjbF0ZbAKqMxL+Mp372xa86PhVyVqFQVpY “你的邮箱
ssh-keygen -t rsa -C “你的邮箱
The key‘s randomart image is:
+---[RSA 2048]----+
| ..=+=+. |
|. +.+Fo . |
| o.o.* o |
|+oo++ = . |
|o.==.o os. |
| *+o . .. |
| ooo.. .. |
|.= .. + |
|*o=.. .. o |
+----[SHA256]-----+
4.查看公钥
cat ~/.ssh/id_rsa.pub
出现提示:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoibHh9t2Vzdfgtjn+GKK4pjpCsuU/qT+G7L2utYvkyHpXwX17WSnmY5GEHiRCM64mGaEklE44K0SQhyVckvhrPA2/bdhgT7RKSkP1aL+rK3nAM2X73argQVR+KKLWtbbk/x7pjDhRq+jr0LIXlzsF38Nt4E1XikgL+/ubU8fGuiJEJacM9Rw9EXjhUw2lchSQ9MmqJRdhXD+e9iKoNmIJyUg1kSt60KTFd5G60kAOjHrQ6zidNmkIhmvamy9eBL4JvBszmjhdDTE3pRgAkgUn5+I41KwDG0AX2DCmAjJMplDJqmmGmleGI6Xd6qI+b6AnPAKwqOTOg29xm2T0XpZp “你的邮箱
//下面这句不用拷贝
ssh-keygen -t rsa -C “你的邮箱
5.拷贝公钥,添加到码云(https://git.oschina.net)中
6.连接到码云
ssh -T [email protected]
出现提示:
The authenticity of host ‘git.oschina.net (103.21.119.119)‘ can‘t be established.
ECDSA key fingerprint is SHA256:FMNC9Kn/eye1W8i89BgrQp+KkGyhjgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no)?
7.输入yes
出现提示:
Warning: Permanently added ‘git.oschina.net,103.21.119.119‘ (ECDSA) to the list of known hosts.
Welcome to [email protected], xxx!
到这里说明SSH公钥已经完成,以后Git管理项目不用输入密码了
8.在git.oschina.net上创建私有或是公开项目
9.选择SSH,复制项目地址,准备用SourceTree管理项目
[email protected]:xxx/xxx.git
10.创建本地git项目存放的目录ABC
11.切换工作目录为ABC
cd xxx/ABC
12.克隆项目到工作目录
git clone [email protected]:xxx/xxx.git
出现提示:
Cloning into ‘weibo‘...
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.
这里表示完成克隆,在ABC目录中会出现工程目录EFG
13.GitHub上下载忽略文件https://github.com/github/gitignore,找到指定类型的忽略文件放到工程目录下,将前面的文件名去掉,去掉之后为隐藏文件(如果在OSChina上选择了忽略文件会冲突,也可以其使用OSChina上的忽略文件)
14.拖动克隆下来的项目文件夹(不是本地工作目录ABC,而是工程目录EFG,否则看不到需要提交文件)到sourceTree中,提交忽略文件到服务器
15.创建项目到EFG目录,Commit->Push项目到OSChina
以上是关于Mac下如何配置OSChina SSH公钥及配置SourceTree的主要内容,如果未能解决你的问题,请参考以下文章