使用 git 拷贝工程,出现了这个错误,解决完成以后在此记录一下:
错误信息:
1
2
3
4
5
Cloning into 'alicloud-ios-demo'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
错误的原因是使用的 git 账户没有配置 ssh 公钥, 打开终端运行命令:
1
ssh-keygen -t rsa -C "Username" #Username 是自己 github 账号的用户名
正常会出现:
1
Enter passphrase (empty for no passphrase):
点击回车,出现
1
Enter same passphrase again:
一直回车,最终生成
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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:PdJjhV1Rr4zLUArRhwCsVKzl5VjegHySqomLKT0beHc Mephsito23
The key's randomart image is:
+---[RSA 2048]----+
| =o+oo . oo.|
| . O =.oo.. .|
| . * O.o..+ .|
| + o o+.+ o . |
| . o S O . o |
|..o o = . |
|o+o . E o |
|=.oo . |
|. .o |
+----[SHA256]-----+
这个就是生成的 ssh 公钥,/Users/mac/.ssh/id_rsa.pub.
是保存的文件路径,
运行命令cat /Users/mac/.ssh/id_rsa.pub
,可以显示出具体公钥字符串( 注意:该命令没有后面的·
),公钥结构如下
1
2
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCmo2m887rNve1q3+Pe1wHubVTZ7/dj39SyRJxgmXsrWvtlU9vdOtENfUbUFVQ/WGbWrYiZSq67xNyTjfou2md+ZMYzStZxU8LngdezkemAU1jEFcHzhBnNbZcjM8N+kk38bbvYtfrsQ
X+eVTWbtAEj9wnoErF6NG9mrYGVL7WJJ/eK46q9JpLp1q...........
然后,我们打开github, 点击setting
->SSH AND GPG Keys
->New SSH key
将公钥复制到这里,保存,然后再次运行 clone 名称拷贝工程,成功!