I spent a decent amount of time figuring out this vague error message, so perhaps this post can save someone else some hassle. I found that many people encountered this problem, posted it on some online forum, but no one gave a clear answer. So here is one possible solution:
Suppose you set up a remote Mercurial repository, cloned it locally via SSH to your machine and then wished to push your changes to the remote repo.
The commands you ran may look something like this:
hg clone ssh://remoteusername@remoteaddr//dir/to/repo/ [... make some changes ...] hg pull hg update [... make some changes ...] hg commit [...] hg push [ssh://remoteusername@remoteaddr//dir/to/repo/]
On the push, if you see:
remote: abort: could not lock repository /dir/to/repo/: Permission denied
you’ll want to check that “remoteusername” has write permissions to not just the “.hg” directory in /dir/to/repo/, but also every file and directory in it. If not, you’ll want to add to the owner group or change the owner of the .hg directory and its contents recursively to “remoteusername” (e.g. using “chown -R”). For obvious reasons, you don’t want to make the directory and its contents globally writable (e.g. don’t “chmod 777”).
I got into this bind by initializing the remote repository under sudo such that the owner was root, and not the username I was using for SSH.