0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MacでGit接続時のURL注意点 完結編

Posted at

はじめに

以前よりMacのSourceTreeを使ってSSHでのGitHub接続を行っているが、上手くいったと思ったら、また繋がらなくなることがあった。
Permission Deniedが出てしまう)
結局のところgitコマンドにて設定してしまうのが1番手っ取り早いことに落ち着いた。

gitの接続先確認

gitリポジトリがあるディレクトリで以下のコマンドを実行

git remote -v

以下のようにsshのURLになっていると接続できない。

origin  ssh://git@github.com/fizz-org/buzz.git (fetch)
origin  ssh://git@github.com/fizz-org/buzz.git (push)

接続先変更

.ssh/configに記載の内容をもとに設定を行う。

configの記載例

Host github.com.hoge
	HostName github.com
	User git
	PreferredAuthentications publickey
	IdentityFile ~/.ssh/id_rsa
    IdentitiesOnly yes
	UseKeychain yes

Git接続URL変更

git remoteにてGitの接続URLを変更する

git remote set-url origin git@github.com.hoge:fizz-org/buzz.git
git remote set-url --push origin git@github.com.hoge:fizz-org/buzz.git

接続URLが変更になっているはず

git remote -v
origin  git@github.com.hoge:fizz-org/buzz.git (fetch)
origin  git@github.com.hoge:fizz-org/buzz.git (push)

念の為sshの接続確認を実施

ssh -T git@github.com.hoge

Hi user! You've successfully authenticated, but GitHub does not provide shell access.
が表示されればOK!

これでSourceTreeからのアクセスも大丈夫!

ポイント

  • configに記載のHost(github.com.hoge)が、git remoteコマンドのoriginの後のホスト名になる
  • git remoteコマンドのfizz-orgはGitHubのorganization
  • ホスト名とorganizationの間は:(コロン)で区切る
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?