换了新电脑,配置了git的ssh keys之后就没怎么动过了,反正配置轻车熟路,就没有测试过。
今天更新一个项目的时候,怎么都更新不了,提示如下:
> git clone git@github.com:xxxxx/xxx
Cloning into 'xxx'...
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.
>
重新检查了密钥对和.ssh的config,都没问题,但是就是报错,折腾了几次,忽然想到一个细节,就是之前试过linux服务器下,ssh的key文件权限必须是400,就是仅限当前用户可读,打开密钥列表一看,果然:
> cd ~/.ssh
> ll
-r-------- 1 imac staff 1.8K 12 28 04:57 old.key
-rw------- 1 imac staff 1.8K 12 28 05:21 new.key
> chmod 400 *.key
> ll
-r-------- 1 imac staff 1.8K 12 28 04:57 old.key
-r-------- 1 imac staff 1.8K 12 28 05:21 new.key
>
可以看到,新的key不知道什么时候变成了600的权限了,改成400之后,再重新git clone,一切OK。