うっかりミスでgit pullできなかった反省

前回の続きでGitを使っていたのだがSSHを使った扱い方に対する知識のなさが露呈したので反省としてまとめてみる。結論としてホスト名を変えていたのを忘れていたことが原因だった。

開発環境↓

% system_profiler SPHardwareDataType
Hardware:

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: MacBookPro16,3
      Processor Name: Quad-Core Intel Core i5
      Processor Speed: 1.4 GHz
      Number of Processors: 1
      Total Number of Cores: 4
      L2 Cache (per Core): 256 KB
      L3 Cache: 6 MB
      Hyper-Threading Technology: Enabled
      Memory: 16 GB
      System Firmware Version: 1554.100.64.0.0 (iBridge: 18.16.14556.0.0,0)

% sw_vers
ProductName:	macOS
ProductVersion:	11.3
BuildVersion:	20E232

% git --version
git version 2.31.1

% zsh --version
zsh 5.8 (x86_64-apple-darwin20.0)

SSHで接続して早速pullしていくぞーという段階から話は始まる。

% git pull origin main
remote: Repository not found.
fatal: repository 'https://github.com/ktnkk/practice-react.git/' not found

git pullに失敗。なんでだろうかと思って設定を閲覧してみた。

% git config --list
credential.helper=osxkeychain
user.name=Keiten Kiki
user.email=oo@kiki.ooo
user.signingkey=WHDP4GJT44VG2VU92FE7SUKZ48H4X6XATDBHTJW9
gpg.program=/usr/local/bin/gpg
commit.gpgsign=true
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
submodule.active=.
remote.origin.url=https://github.com/ktntt/practice-react.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
pull.rebase=false

remote.origin.urlhttpsになっていることを発見してしまった。そういえばこの前までHTTPSで接続してたっけ。

% git remote set-url origin git@github.com:ktnkk/practice-react.git

なので改めてURLを登録。

% git config --list
credential.helper=osxkeychain
user.name=Keiten Kiki
user.email=oo@kiki.ooo
user.signingkey=WHDP4GJT44VG2VU92FE7SUKZ48H4X6XATDBHTJW9
gpg.program=/usr/local/bin/gpg
commit.gpgsign=true
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
submodule.active=.
remote.origin.url=git@github.com:ktnkk/practice-react.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
pull.rebase=false

ちゃんと変わっていることを確認。

% git pull origin main
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.

ここで再度git pullを試みるがまたもや失敗。なんでかな。

% ssh -vT github_p
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/ki/.ssh/config
debug1: /Users/ki/.ssh/config line 1: Applying options for github_p
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to github.com port 22.
debug1: Connection established.
debug1: identity file /Users/ki/.ssh/id_rsa_github_private type 0
debug1: identity file /Users/ki/.ssh/id_rsa_github_private-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version babeld-c34a939f
debug1: no match: babeld-c34a939f
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:Nz5kdxTXWPSburf4STKM3h29FVW86ezjTZ2WZVTRsKB
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/ki/.ssh/known_hosts:1
Warning: Permanently added the RSA host key for IP address '52.192.72.89' to the list of known hosts.
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/ki/.ssh/id_rsa_github_private RSA SHA256:6n7Z+Vc5AgkN/bVuS6goCVBdoq34L26v/65yf7YVxYw explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/ki/.ssh/id_rsa_github_private RSA SHA256:6n7Z+Vc5AgkN/bVuS6goCVBdoq34L26v/65yf7YVxYw explicit
debug1: Server accepts key: /Users/ki/.ssh/id_rsa_github_private RSA SHA256:6n7Z+Vc5AgkN/bVuS6goCVBdoq34L26v/65yf7YVxYw explicit
Enter passphrase for key '/Users/ki/.ssh/id_rsa_github_private':
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([52.192.72.89]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LC_TERMINAL_VERSION = 3.4.4
debug1: Sending env LANG = ja_JP.UTF-8
debug1: Sending env LC_TERMINAL = iTerm2
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi ktnkk! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3564, received 2724 bytes, in 0.4 seconds
Bytes per second: sent 9029.9, received 6901.6
debug1: Exit status 1

SSHをデバッグモードで接続してみる。すると普通に接続できたぞ。ここで全てを理解した。

% git remote set-url origin git@github_p:ktnkk/practice-react.git

自分でホスト名をgithub_pにしていたのにデフォルトのホスト名を使っていたことが原因だった。なんともお粗末な。

% git pull origin main
Enter passphrase for key '/Users/ki/.ssh/id_rsa_github_private':
From github_p:ktnkk/practice-react
 * branch            main       -> FETCH_HEAD
Already up to date.

これでバッチリ成功。ホスト名を変えるときは気を付けよう。

To comment

@TOC
閉じる