Troubleshooting of GIT

From LemonWiki共筆
Revision as of 14:39, 4 June 2026 by Planetoid (talk | contribs) (Created page with " == Troubleshooting of GIT == === Restoring deleted files in Git === Restoring deleted files in Git === SSH Authentication Failed: Permission denied (publickey) === '''Error Message''' After keyin the command <pre>git clone [email protected]:your-org/your-repo.git /opt/your-app</pre>, met the error message <pre> Cloning into '/opt/your-app'... [email protected]: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Troubleshooting of GIT[edit]

Restoring deleted files in Git[edit]

Restoring deleted files in Git

SSH Authentication Failed: Permission denied (publickey)[edit]

Error Message

After keyin the command

git clone [email protected]:your-org/your-repo.git /opt/your-app

, met the error message

Cloning into '/opt/your-app'...
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

Cause

This error occurs when Git cannot authenticate with GitHub over SSH. This typically means the SSH key on your machine is either missing, not registered with your GitHub account, or not being picked up by the SSH agent.

Solutions

Option 1 — Configure your SSH config file

Add an entry to `~/.ssh/config` so Git automatically uses the correct key:

Host github.com
  HostName github.com
  User git
  IdentityFile /path/to/.ssh/your_key_name

Option 2 — Pass the SSH key inline

1. Before running `git clone`, test whether the specified SSH key can successfully authenticate with GitHub:

ssh -T -i /path/to/.ssh/your_key_name [email protected]

If the key is configured correctly, you should see:

Hi your-org/your-app! You've successfully authenticated, but GitHub does not provide shell access.

`successfully authenticated` confirms the key is correctly linked to your GitHub account and you're good to proceed with `git clone`. The message `GitHub does not provide shell access` is expected — SSH is used for Git operations only, not for interactive shell login.

2. Override the SSH command directly when cloning:

sudo GIT_SSH_COMMAND='ssh -i /path/to/.ssh/your_key_name -o IdentitiesOnly=yes' \
  git clone [email protected]:your-org/your-repo.git /opt/your-app

Icon_exclaim.gif Notice: `-o IdentitiesOnly=yes` prevents SSH from trying other keys loaded in the agent, which can cause unexpected auth failures.

Further Reading[edit]