終端連接oschina 生成SSH公鑰
利用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. |
|
| 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
終端連接oschina 生成SSH公鑰