Gitのリポジトリサーバへのアクセスが、SSH経由というのはよくあると思います。こんな感じで
git clone ssh://severname/repository/project.git
その際、認証がID+パスワードではなく、ID+秘密鍵の場合もあると思います。その際、Gitでの認証はどうしたら良いのでしょうか?一般的なGitのクライアントソフトの場合、認証キーを指定することが出来ます。一方で、Gitのコマンドの場合、認証に関わる指定はなさそうに見えます。(git --helpをご覧あれ)
$ git --help
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
See 'git help <command>' for more information on a specific command.
これをどう解決するのかというと、gitコマンドではなくsshの設定で解決せよとのことです。
~/.ssh/の下にconfigファイルを配置しておくと、sshの際に設定を読みにいくようになります。Hostがマッチするものがあれば、その中に記載されているUser名やパスワードもしくはIdentityFile(認証に使うファイル)を自動的に読み取るようになります。GitHubでの例だと、次のようになります。PortとかTCPKeepAlive,IdentitiesOnlyはオプションなので特に指定しなくても大丈夫です。
Host github.com User git Port 22 Hostname github.com IdentityFile ~/.ssh/github_rsa TCPKeepAlive yes IdentitiesOnly yes
管理者側の視点にたてば、Gitのアカウントを一人ひとり管理するのは果てしなく面倒くさいと思います。その際は、gitolite等を導入するのが良いのかなと思います。それについてはまた次回。