3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

初心者がgit cloneでぶつかったエラー

Last updated at Posted at 2021-07-25

###git cloneとは
リモートリポジトリをローカルリポジトリに複製すること
複製という意味は理解してましたが、何をどうしていたかは知らなかったのでしっかり理解すべきだと思いました。

####初めてgit cloneした時のエラー文

Permission denied (publickey). fatal: Could not read from remote 
repository.  Please make sure you have the correct access rights
 and the repository exists.

######どんな問題が発生しているか。
リモートリポジトリに対してアクセス権が無く、エラーになった。

####解決方法

######1.プライマリーキーの作成

ssh-keygen -t rsa -C メールアドレス

メールアドレスはgithub登録した時と同じものにしてください。

すると順番にこのように表示されます。

Enter file in which to save the key (/home/vagrant/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

上から、
・鍵の保存場所の指定
・パスワードの設定
・パスワードの再入力

入力後エンターで先に進めます。

#####2.作成した鍵をコピーする。

ls ~/.ssh/

id_rsaが秘密鍵
id_rsa.pubが公開鍵

#####3.id_rsa.pubを表示する

less ~/.ssh/id_rsa.pub

id_rsa.pubファイルを開いて公開鍵の確認
sshから始まる長い文字列が表示されるので末尾のメールアドレスまでをコピーしておきます。

#####4.githubで鍵を登録する
githubのマイページで、この鍵を登録します。
右上のアイコンをクリックし、settings → SSH and GPG keysをクリックしします。
次に、右上のnew keysをクリックしてください。

すると鍵の登録画面が現れます。
Keyのところに先程コピーしたものを貼り付けます。

#####5.ターミナルにてconfigを設定し、疎通確認をする

vim ~/.ssh/config   

configの内容はこちら

Host github
  HostName github.com
  IdentityFile ~/.ssh/id_rsa
  User git

git cloneを再び実行すると、パスワードを求められるので設定したパスワードを入力し、クローン完了です。

###参考資料

3
2
2

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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?