LoginSignup
14
9

More than 3 years have passed since last update.

git cloneする際にGithubのusernameとpasswardを入力したが失敗する

Posted at

最近の勉強で学んだ事を、ノート代わりにまとめていきます。
主に自分の学習の流れを振り返りで残す形なので色々、省いてます。
Webエンジニアの諸先輩方からアドバイスやご指摘を頂けたらありがたいです!

Githubのusernameとpasswardを入力したが失敗する

リモートリポジトリをgit cloneしようとした際にうまくできずに以下のエラーが発生しました。

$ git clone https://github.com/hoge/hoge.git
Cloning into 'hoge'...
Username for 'https://github.com': hoge
Password for 'https://hoge@github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/hoge/hoge.git/'

GitHubへのアクセスを確認したところ

$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
git@github.com: Permission denied (publickey).
$ git remote -v
fatal: not a git repository (or any of the parent directories): .git

Warning: Permanently added the RSA host key for IP address ‘52.74.223.119’ to the list of known hosts.
この記事によると現在のgithubプロジェクトの問題部分にアクセスする権限がないのが原因と思われます。最初にpublickKeyを作成する必要があるみたいです。

一度、sshでgit cloneで行うと以下のような結果になりました。

$ git clone git@github.com:hoge/hoge.git
Cloning into 'hoge'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

この問題のポイント
・対象のリモートリポジトリへのアクセス権限がなく失敗した。

解決策
・鍵認証周りを再設定し直す。
よって、解決までの流れは
1:鍵を作成する。
2:作成した鍵をコピーする。
3:gitghubに公開鍵を登録する。
4:configファイルを作成し直す。(接続確認)

こちらの記事を参考にし手順通り行うと問題なくgit cloneできました!

【git エラー解決策】Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. が出た時の解決方法

14
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
9