git倉庫配置git ssh

weixin_34107955發表於2017-11-30

貌似現在寫程式碼少不了要用git,前兩天電腦壞了,換了臺新電腦,所有配置都要重新做,記一下git倉庫配置git ssh的步驟

1、使用git前需要開啟一次Xcode,使用Xcode同意git的使用者協議

2、配置使用者名稱和密碼

$ git config --global user.name "myname"
$ git config --global user.email "myname@xxx.com"

3、生成ssh key

$ ssh-keygen -t rsa -C "myname"
Creates a new ssh key using the provided email # Generating public/private rsa key pair.

Enter file in which to save the key (/home/you/.ssh/id_rsa):

直接按Enter,要求需要輸入密碼,直接按Enter

4、新增公鑰到git倉庫

檢視公鑰

$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/pHeryK3ktnrFW0bEnb/wwgoSYprQk0fApmvjVMg1OkjfgbdEKJ2i63HDBlop1QeS8PBpkaBuu9H8knFyRS4WjBBHwFHH+HBEIyY04lbjh3iOJLArghFjUh9bW2oTfCLmxWLfh/UjO0BmjHb0raRR10Q5W5aUI7V9uHjjCaDoitwGUIMCiGD7vBWruz3Ky4/OxLVh4gRsp4236NVCBanaPvgcWjsSC2XQu9mmB/v/hL7G6/qOzPhc5N3I6GU5zyd8mhhAmX6lOJW4Yrw1jVaDevJl5d+33tCYK42tzqMvJQ7Wmb0g4sGAu207ZEhOKC6cpcj6cXFdENQKDKbFOBGT myname

登入git倉庫,在Profile Settings->SSH Keys->Add an SSH key,將公鑰新增進去。

5、測試git

$ git clone git@git.xxx.com:group:project.git
Cloning into 'project'...
Bad owner or permissions on /Users/MyUser/.ssh/config
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

6、新增config檔案

$ vim ~/.ssh/config

新增以下內容

Host *
HostKeyAlgorithms +ssh-dss

儲存,退出,再執行clone命令成功

相關文章