0%

GitHub使用SSH模式不能用sudo

今天在AWS上用git时一直报错:

1
2
3
4
5
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

因为我在/home/www下进行的操作,这个目录当前用户是没有写权限的,所以需要在操作git时前边加sudo,所以才会导致这个问题。

官方说明:

You should not be using the sudo command with Git. If you have a very good reason you must use sudo, then ensure you are using it with every command (it’s probably just better to use su to get a shell as root at that point). If you generate SSH keys without sudo and then try to use a command like sudo git push, you won’t be using the same keys that you generated.

解决方法,将www目录权限改为777。