问题描绘与排查
今天进行对一个repo进行git clone报错如下:
git clone git@github.com:JiexingQi/picard.git
Cloning into 'picard'...
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.
参阅网上的博客,咱们能够先运用这个命令来检查一下.
(picard) jxqi@han-server-01:~/text2sql$ ssh -T git@github.com
git@github.com: Permission denied (publickey).
果不其然,连正常的github都无法衔接。提示咱们短少ssh公钥(publickey)。因此考虑是否在该服务器上正确装备ssh密钥信息。
能够运用如下命令进行检查是否存在ssh装备文件:
ls -al ~/.ssh
显现结果如下:
(picard) jxqi@han-server-01:~/text2sql$ ls -al ~/.ssh
total 16
drwxrwxr-x 2 jxqi jxqi 4096 Dec 20 17:02 .
drwxr-xr-x 17 jxqi jxqi 4096 Feb 11 16:43 ..
-rw-rw-r-- 1 jxqi jxqi 2302 Jan 25 09:38 authorized_keys
-rw-r--r-- 1 jxqi jxqi 1110 Jan 4 09:55 known_hosts
能够看到,这里短少本地SSH 密钥。
问题解决
找到问题后,咱们只需正确装备ssh密钥即可。装备命令如下:
ssh-keygen -t rsa -b 4096 -C "*********@qq.com"
这里只需要填写自己的github上的注册邮箱即可。我这里是qq邮箱。
反应结果如下:
(picard) jxqi@han-server-01:~/text2sql$ ssh-keygen -t rsa -b 4096 -C "*******@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jxqi/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jxqi/.ssh/id_rsa.
Your public key has been saved in /home/jxqi/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:VmyKNm5jC98ewW/BJ0f+ydD5JcMD2zUsxlcGn4XNj3rYs ********@qq.com
The key's randomart image is:
+---[RSA 4096]----+
| .+=|
| . .o+|
| + o. k++|
| o = od *+o*|
| + S + * O++|
| o o o = +.*.|
| . = . o .+..|
| = + o E . |
| o.o |
+----[SHA256]-----+
之后检查ssh装备文件和github衔接状况。
(picard) jxqi@han-server-01:~/text2sql$ ls -al ~/.ssh
total 24
drwxrwxr-x 2 jxqi jxqi 4096 Feb 13 14:06 .
drwxr-xr-x 17 jxqi jxqi 4096 Feb 11 16:43 ..
-rw-rw-r-- 1 jxqi jxqi 2302 Jan 25 09:38 authorized_keys
-rw------- 1 jxqi jxqi 3243 Feb 13 14:06 id_rsa
-rw-r--r-- 1 jxqi jxqi 743 Feb 13 14:06 id_rsa.pub
-rw-r--r-- 1 jxqi jxqi 1110 Jan 4 09:55 known_hosts
(picard) jxqi@han-server-01:~/text2sql$ ssh -T git@github.com
Hi JiexingQi! You've successfully authenticated, but GitHub does not provide shell access.
能够看到,现已能够正常衔接了,接下来进行git clone就顺畅很多了。
(picard) jxqi@han-server-01:~/text2sql$ git clone git@github.com:JiexingQi/picard.git
Cloning into 'picard'...