On Ubuntu 20.04, I installed the gh
CLI tool via:
sudo snap install gh
Then, trying to gh repo clone
a public repo resulted in the error:
Error: warning: unable to access '/etc/gitconfig': Permission denied
This happened via HTTPS, and SSH with freshly generated key. Related QAs like this one point at the possibility of an issue with installation.
How to fix this, so I can have the closest thing to the good old clone with SSH key?
Likely, the snap
installation was encapsulated and somehow unable to access the GitHub config file. The simplest fix in this case was to uninstall the CLI tool and reinstall it following the official docs:
# remember to logout from GH if you haven't done so...
gh auth logout
sudo snap remove gh
Now, on a new terminal (to refresh the snap-related environment variables), install via the following official steps (should work on any Debian-based system):
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
At this point we're all set. Authenticate via your favorite method (I chose HTTPS via browser), and cloning should work without issues:
gh auth login
gh repo clone <YOUR_REPO>
Hope this helps!
Cheers,
Andres