在使用git fetch时遇到下面这样的问题:
$ git fetch
zhoumin@abc.cn: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
查了一下,是因为~/.ssh/id_rsa.pub里面的内容被别人更新了,以前都是重新再生成一遍,然后将更新后的id_rsa.pub加入到远端服务器上,但老这样搞,也挺麻烦。在网上查了一下,原来ssh在运行时可以指定public key,下面就记录一下具体过程。
第一步:生成自己的ssh key
注意两点:1、指定自己的邮箱,2、指定自己的public key文件
例如:下面我指定的邮箱是:zhoumin@abc.cn,指定的key文件是:/home/public/.ssh/id_rsa_zm
$ ssh-keygen -t rsa -C zhoumin@abc.cn
Generating public/private rsa key pair.
Enter file in which to save the key (/home/public/.ssh/id_rsa): /home/public/.ssh/id_rsa_zm
...
...
...
第二步:使用 git config -l 确认user.email 和上面生成public key时使用的邮箱是否一样
第三步:使用下面命令配置git 的core.sshCommand变量
$ git config core.sshCommand "ssh -i /home/public/.ssh/id_rsa_zm -F /dev/null"
第四步:将public key (id_rsa_zm.pub里面的内容)添加进远端服务器的SSH Public Key中
第五步:使用git fetch 重新拉取代码,这下应该就好了