当我们第一次使用git 命令想从Github 中下载文件时,可能会遇到:
Permission denied (publickey).
fatal: Could not read from remote repository.
Pleasemake sure you have the correct access rightsand the repository exists.
分析原因:由于在本地(或者服务器上)没有生成ssh key
解决方案:在本地生成ssh key,然后添加到我们自己的Github 账户的SSH中
1)首先,如果你没有ssh key的话,在ternimal下输入命令:ssh-keygen -t rsa -C "youremail@example.com", youremail@example.com改为自己的邮箱即可,途中会让你输入密码啥的,不需要管,一路回车即可,会生成你的ssh key。(如果重新生成的话会覆盖之前的ssh key。)
例如:
ssh-keygen -t rsa -C "12345678@qq.com"
其中12345678@qq.com,改为自己的邮箱。
2)进入目录ssh
cd ~/.ssh
查看一下目下的内容:
执行:ls
会看到 id_rsa.pub 文件,这个文件就是SSH Key的内容。
3)登录自己的github帐号,,在settings下,SSH and GPG keys下new SSH key,title随便取一个名字,然后将id_rsa.pub里的内容复制到Key中,完成后Add SSH Key。
4)最后一步,验证Key
在ternimal下输入命令:
ssh -T git@github.com
提示:Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
这时候你的问题就解决啦,可以使用命令 git clone --recursive git@github.com:peiyunh/tiny.git 去下载你的代码啦。
希望对你有帮助。