我已经使用以下命令在Ubuntu上安装了git
:
sudo apt-get install git -y
我不以root用户身份登录。我以普通用户身份登录。但每当我尝试使用git
时,我都会收到以下错误:
error: cannot open .git/FETCH_HEAD: Permission denied
如果我使用sudo
,它就被解决了。
我该怎么解决这个问题?我不想被强迫总是用sudo作为git命令的前缀。
此外,我无法提取我现有的回购,我得到了这个错误:
hostkeys_find_by_key_hostfile: hostkeys_foreach failed for /root/.ssh/known_hosts: Too many levels of symbolic links
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ED25519 key fingerprint is SHA256:*************.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/root/.ssh/known_hosts).
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
似乎是权限问题。也许你做了最初的clone
作为根?
您可以使用ls -l .git
查看当前所有者/组
如果您想将所有者更改为自己,请使用
sudo chown -R "$USER" -- /path/to/your/local/repo/folder
要查看命令的更改,请使用类似于以下的添加--changes
:
sudo chown -R --changes "$USER" -- /path/to/your/local/repo/folder
在修复权限后,你也应该能够拉(没有sudo(