Mac(OS X El Capitan)にてbrew updateしたら「fatal: cannot create directory at ‘.github’: Permission denied」

「OS X El Capitan」にしたら元々インストールしていた、
homebrewで更新しようとしたらエラーが出たのでメモとして。

$ brew update
warning: unable to unlink CONTRIBUTING.md: Permission denied
warning: unable to unlink SUPPORTERS.md: Permission denied
fatal: cannot create directory at '.github': Permission denied
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master
$ sudo chown -R $USER:admin /usr/local
$ cd /usr/local/
$ git reset --hard origin/master
HEAD is now at 53c5089 CoreTap#install: fix clone target setting
$ brew update
remote: Counting objects: 456, done.
remote: Compressing objects: 100% (413/413), done.
remote: Total 456 (delta 26), reused 335 (delta 17), pack-reused 0
Receiving objects: 100% (456/456), 706.29 KiB | 276.00 KiB/s, done.
Resolving deltas: 100% (26/26), done.
From https://github.com/Homebrew/brew
 + 53c5089...d7aa0c0 master     -> origin/master  (forced update)
HEAD is now at d7aa0c0 scm/git: prevent exec bomb with 'env :userpaths'
==> Tapping homebrew/core
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 3656, done.
remote: Compressing objects: 100% (3539/3539), done.
remote: Total 3656 (delta 14), reused 1569 (delta 5), pack-reused 0
Receiving objects: 100% (3656/3656), 2.70 MiB | 431.00 KiB/s, done.
Resolving deltas: 100% (14/14), done.
Checking connectivity... done.
Tapped 3531 formulae (3,682 files, 8.5M)
Updated 1 tap (homebrew/dupes).
==> Updated Formulae
homebrew/dupes/ed                      homebrew/dupes/gzip                    homebrew/dupes/nano                    homebrew/dupes/openssh               
homebrew/dupes/file-formula            homebrew/dupes/krb5                    homebrew/dupes/ncurses                 homebrew/dupes/rsync                 
homebrew/dupes/grep                    homebrew/dupes/lapack                  homebrew/dupes/openldap                homebrew/dupes/whois                 
==> Deleted Formulae
homebrew/dupes/gdb

ついでにAnsibleが古かったので更新しておく。

$ brew upgrade ansible
==> Upgrading 1 outdated package, with result:
ansible 2.0.1.0
==> Upgrading ansible
==> Installing dependencies for ansible: libyaml, openssl
==> Installing ansible dependency: libyaml
==> Downloading https://homebrew.bintray.com/bottles/libyaml-0.1.6_1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libyaml-0.1.6_1.el_capitan.bottle.tar.gz
🍺  /usr/local/Cellar/libyaml/0.1.6_1: 8 files, 312.8K
==> Installing ansible dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2g.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2g.el_capitan.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs
 
and run
  /usr/local/opt/openssl/bin/c_rehash
 
This formula is keg-only, which means it was not symlinked into /usr/local.
 
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
 
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
 
    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include
 
==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2g: 1,678 files, 12.0M
==> Installing ansible
==> Downloading https://homebrew.bintray.com/bottles/ansible-2.0.1.0.el_capitan.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring ansible-2.0.1.0.el_capitan.bottle.2.tar.gz
==> Caveats
Homebrew writes wrapper scripts that set PYTHONPATH in ansible's
execution environment, which is inherited by Python scripts invoked
by ansible. If this causes problems, you can modify your playbooks
to invoke python with -E, which causes python to ignore PYTHONPATH.
==> Summary
🍺  /usr/local/Cellar/ansible/2.0.1.0: 8,167 files, 84.8M

[ git ][ Mac ] Macにgitをインストールしてそのままgithubにも登録

まずはMacにgitをインストールしてみる

MacPortsでインストール

# sudo port install git-core +svn

エラーが出た

# Error: Target org.macports.activate returned: Image error:
/opt/local/lib/perl5/5.8.8/darwin-2level/auto/List/Util/Util.bs is
being used by the active perl5.8 port.  Please deactivate this port
first, or use the -f flag to force the activation.
# Error: The following dependencies failed to build:
p5-scalar-list-utils p5-svn-simple subversion-perlbindings apr
apr-util cyrus-sasl2 neon serf subversion p5-term-readkey rsync popt
# Error: Status 1 encountered during processing.

そういえばportのアップデートなども行っていなかったな・・・ちゃんとやろう。

自分の環境では「/usr/local/src/localports」に設定してあったので、そこまで移動してportindex

# cd /usr/local/src/localports
# sudo portindex

次にアップデートを行った

# sudo port -d selfupdate

# 既にgitをインストールされている場合はdeactivateする
# インストールされていないと下記のようにエラーが出る

# sudo port deactivate git-core
# Error: port deactivate failed: Registry error: git-core not
registered as installed & active.

ではインストール

# sudo port install git-core +gitweb +svn
.........
--->  Installing git-core @1.6.3.3_0+doc+gitweb+svn
--->  Activating git-core @1.6.3.3_0+doc+gitweb+svn
--->  Cleaning git-core

インストール完了。これで準備が整ったので、そのままgithubに登録したのでその手順をメモメモ。

ここからはgithubへの登録手順

githubのURLはこちらgithub.comからアクセス可能

1. ユーザー登録

まずはユーザー登録するのだが、ここで「SSH Public Keys」を登録する項目があるのだが未入力でスルーした。
# 後で登録も出来るし追加もで出来るので問題無い。
登録すると自分のホーム画面となる。

github01
github01 posted by (C)kishir

画面にある「Create a Repository」からレポジトリを作成する。リンクをクリックするとレポジトリの作成画面となる。
ここで入力するのはとりあえず「Project Name」だけでOK。

github02
github02 posted by (C)kishir

そうするとgitのレポジトリが作成されて、設定方法が表示されるので指示に従って行う。

github03
github03 posted by (C)kishir

2. 「SSH Public Keys」の作成と登録 (ここからはMacでの作業

# 今回は公開鍵を「id_rsa」では無く「github_id_rsa」で行っています。

# 参考ページはhttp://github.com/guides/providing-your-ssh-key#macosx-3

# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/tom/.ssh/id_rsa): ← ファイル名はid_rsaでOK? いや今回は違う名前が良いので、github_id_rsaを打ってエンター
Enter passphrase (empty for no passphrase): ← パスワードの設定
Enter same passphrase again: ← 上記のパスワードを再入力
Your identification has been saved in /Users/.ssh/github_id_rsa.
Your public key has been saved in /Users/.ssh/github_id_rsa.pub.

これで公開鍵のペアが完成したので、そいつらを「.ssh」以下に移動

# mv github_id_rsa .ssh/
# mv github_id_rsa.pub .ssh/
次に先ほど作成したgithub_id_rsaの中身をクリップボードへコピーする

# cat github_id_rsa.pub | pbcopy

これでコピーされているはずなので、そのままgithubサイトの公開鍵設定のテキストエリアへ貼り付ける。

# 公開鍵は会社用や自宅用など複数の設定が可能

configファイルの設定は「.ssh/config」
に下記を追記する。

これはホスト名が「github.com」の場合は、この設定で行うよ!ってことがつらつらと書かれている。
# githubサイトに記載されている

Host github.com
 User git
 Port 22
 Hostname github.com
 IdentityFile ~/.ssh/github_id_rsa
 TCPKeepAlive yes
 IdentitiesOnly yes