git仓库配置git ssh

貌似现在写代码少不了要用git,前两天电脑坏了,换了台新电脑,所有配置都要重新做,记一下git仓库配置git ssh的步骤

1、使用git前需要打开一次Xcode,使用Xcode同意git的用户协议

2、配置用户名和密码

$ git config --global user.name "myname"
$ git config --global user.email "[email protected]"

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 [email protected]: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命令成功

你可能感兴趣的:(git仓库配置git ssh)