LoginSignup
51
49

More than 5 years have passed since last update.

gitとsshのconfigについて(備忘録)

Last updated at Posted at 2017-07-07

自分のgitとsshの鍵管理や設定を書き留めておきます.参考になるかわかりませんが...笑

鍵作成

他のサイトにたくさん書いてる

$ ssh-keygen -t rsa

.ssh/configについて

sshの公開鍵と秘密鍵はそれぞれで作っています(管理しやすいかなと思いまして).それぞれのディレクトリに公開鍵と秘密鍵が格納されている感じです.

~/.ssh
ls -l | grep ^d
drwxr-xr-x 4 hogehoge staff  136  7  7 21:32 bitbucket
drwx------ 4 hogehoge staff  136  4 28 19:54 gitbucket
drwxr-xr-x 4 hogehoge staff  136  7  7 21:33 github
drwxr-xr-x 5 hogehoge staff  170  7  6 14:21 myserver

以下が~/.ssh/configの中身(一部だけ)

~/.ssh/config
Host Myserver 
    HostName  (適当なIPアドレス or FQDN)
    Port 22(設定したやつ)
    IdentityFile ~/.ssh/myserver/id_rsa
    User hogehoge

Host BitBucket
    HostName bitbucket.org(絶対これ)
    IdentityFile ~/.ssh/bitbucket/id_rsa
    TCPKeepAlive yes
    IdentitiesOnly yes
    User git(任意)

Host GitHub
    HostName github.com(絶対これ)
    IdentityFile ~/.ssh/github/id_rsa
    TCPKeepAlive yes
    IdentitiesOnly yes
    User git(絶対これ)

GitHubのUserは必ずgitじゃないとうまくいかなかったです.BitBucketは任意でもいけたが,GitHubと揃える形でgitにしました.

.git/configについて

GitHubバージョン

リポジトリ名/.git/config
[core]
    repositoryformatversion = 0
    filemode = true
    logallrefupdates = true
    precomposeunicode = true
[remote "origin"]
    url = GitHub:(ユーザ名)/(リポジトリ名).git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
    rebase = false

BitBucketバージョン

リポジトリ名/.git/config
[core]
    repositoryformatversion = 0
    filemode = true
    logallrefupdates = true
    precomposeunicode = true
[remote "origin"]
    url = BitBucket:(ユーザ名)/(リポジトリ名).git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
    rebase = false

urlの部分が違うだけです."GitHub"や"Bitbucket"は.ssh/configで設定したHostと同じものにします.ユーザ名はそれぞれのサービスのユーザ名にします.(.ssh/configのUserではありません!)

51
49
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
51
49