LoginSignup
1

More than 3 years have passed since last update.

[Github] pushしたら Authentication Error - "remote: Invalid username or password"というエラーが発生

Last updated at Posted at 2019-09-09

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

起きたエラー

作成したリモートファイルにgit pushを行う際に以下の問題が発生しました。
git pushした際にusernameとpasswordを求められ、正しいものを答えても認証に失敗する。

$ git push -u origin master
Username for 'https://github.com': 
Password for 'https://github.com': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/hoge/hoge.git/'

解決方法

該当するリポジトリまで移動し、Vimでvi .git/configを開きます。

core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
[remote "origin"]
        url = https://github.com/hoge/hoge.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

この様になっています。
この[remote "origin"]内の
url = https://github.com:hoge/repository.git
のurlがHTTPSのものを以下の様にSSHのurlに変更してあげると
url = git@github.com:hoge/hoge.git
これでusernameとpasswordは聞かれずにpushすることができます。

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
1