ã¯ããã«
æ¬èšäºã§ã¯ã¿ã€ãã«ã®å
容ã«å ã㊠~/.ssh/config
ã«å¯Ÿããåºæ¬çãªç解ãæ·±ãããããåçš®èšå®é
ç®ã«é¢ãã説æãä»éããŠè¡ããŸããGitHub ãäŸã«æããŠã¯ãããã®ã®ãBitbucket ã GitLabãGit ãµãŒããžæ¥ç¶ããéã«ãå©çšå¯èœãª ~/.ssh/config
ã®èšå®ã«ã€ããŠèšèŒããŠãããŸãã
~/.ssh/config
ã®æžãæ¹
ãŸã GitHub ãžæ¥ç¶ãã ~/.ssh/config
ã®èšå®ãèŠãŠãããŸããGitHub ã§èªèšŒã«äœ¿çšãã SSH ããŒã¯ç»é²æžã¿ã§ç§å¯éµã¯ ~/.ssh/github
ãžé
眮ããŠããæ³å®ã§ãã
SSH ããŒãæªç»é²ã®å Žåã¯ å ¬åŒãµã€ãã®æé ã«åŸã£ãŠéµã®çæã»ç»é²ãŸã§ãè¡ã£ãŠãããŸãã
# ~/.ssh/config
Host github.com
IdentityFile ~/.ssh/github
User git
~/.ssh/config
ã®åçš®èšå®é
ç®ã¯äžèšã«ãªããŸãã
é ç® | 説æ |
---|---|
Host | ãã¹ãåãæå®ãã |
IdentityFile | æ¥ç¶æã«äœ¿çšããç§å¯éµãæå®ãã |
User | æ¥ç¶æã®ãŠãŒã¶åãæå®ãã |
èšå®ãè¡ãããšã§ github.com
ã« SSH æ¥ç¶ããéããŠãŒã¶åã« git
ãæå®ããã~/.ssh/github
ã«ååšããç§å¯éµãçšã㊠SSH æ¥ç¶ãè©Šã¿ãããã«ãªããŸãã
æ©é github.com
æ¥ç¶æã«æ£ããèªèšŒãéã£ãŠããã確èªãããããé©åœãªãã©ã€ããŒããªããžããªã git clone
ããŠã¿ãŸãã
ãã©ã€ããŒããªããžããªã git clone
ããå®è¡çµæ (æå)
ç¡äºã« git clone
ã§ããããšã確èªã§ãããæåã§ãã
æ¥ç¶å ã«å¿ããŠç§å¯éµã䜿ãåããã
GitHub ã§åžžã«åäžã®ç§å¯éµãçšããŠèªèšŒãè¡ãéã¯åé¡ãªãã®ã§ãããäŸãã° GitHub ã¢ã«ãŠã³ãããã©ã€ããŒãçšãšä»äºçšã§äœ¿ãåããŠããŠããªããžããªå ã«å¿ããŠç§å¯éµã䜿ãåããããšããã±ãŒã¹ã¯ãããšæããŸãã
ãã®å Žå㯠~/.ssh/config
ã®èšå®ãš git
ã®ãªã¢ãŒããªããžããªãžã®æ¥ç¶æ
å ±ãå€æŽããããšã§å¯Ÿå¿å¯èœã§ãã
äŸãã°ãã©ã€ããŒãçšã® GitHub ã¢ã«ãŠã³ã A
ãšä»äºçšã® GitHub ã¢ã«ãŠã³ã B
ãååšãããšããŸãããã®é github-A
ããã¹ãã®æ㯠A
ã®ç§å¯éµããgithub-B
ããã¹ãã®æ㯠B
ã®ç§å¯éµãå©çšããããã®èšå®ã¯äžèšã«ãªããŸãã
# ~/.ssh/config
# ãã©ã€ããŒãçšã® GitHub ã¢ã«ãŠã³ãã§å©çšããæ¥ç¶èšå®
Host github-A
HostName github.com
IdentityFile ~/.ssh/github-A
User git
# ä»äºçšã® GitHub ã¢ã«ãŠã³ãã§å©çšããæ¥ç¶èšå®
Host github-B
HostName github.com
IdentityFile ~/.ssh/github-B
User git
æ°ãã« HostName
ãšããé
ç®ãèšå®ããŸãããHostName
ã«ã¯æ¥ç¶å
ãæå®ããŸããHostName
ã¯äœãæå®ããªãå Žå Host
ãšåãå€ãèšå®ãããŸãã
ä»åã¯åäžæ¥ç¶å
ã«å¯ŸããŠã¢ã«ãŠã³ããåãæ¿ãããã®ã§ãHost
ã«ã¯ã¢ã«ãŠã³ãèå¥å¯èœãªå€ (ex: github-A
, github-B
, etc.) ããHostName
ã«æ¥ç¶å
ã§ãã github.com
ãæ瀺çã«æå®ããŠã¢ã«ãŠã³ãæ¯ã«èšå®ããããŸããã
次㫠git
ã®ãªã¢ãŒããªããžããªãžã®æ¥ç¶æ
å ±ãå€æŽããŸãã
~/.ssh/config
ã« User
ãæå®ããŠããå Žåã¯è©²åœ Host
ãžæ¥ç¶æã«èªåçã«ãŠãŒã¶ãèšå®ããããããæ¥ç¶ URL ãããŠãŒã¶åã§ãã git
ã¯åãé€ããŠãåé¡ãããŸããã
# çŸåšã®ãªã¢ãŒããªããžã㪠URL
git remote -v
origin git@github.com:nikaera/private-repository.git (fetch)
origin git@github.com:nikaera/private-repository.git (push)
# ãªã¢ãŒããªããžã㪠URL ã
# git@github.com:nikaera/private-repository.git ãã
# github-A:nikaera/private-repository.git ã«å€æŽãã
# (ãŠãŒã¶åã® git ã¯å€æŽå
ããåãé€ããŠãã)
git remote set-url origin github-A:nikaera/private-repository.git
# æ°ãã«èšå®ãããªã¢ãŒããªããžã㪠URL
git remote -v
origin github-A:nikaera/private-repository.git (fetch)
origin github-A:nikaera/private-repository.git (push)
ãã®ç¶æ
ã§å
ã»ã© git clone
ããŠãããã©ã€ããŒããªããžããªå
㧠git ls-remote origin
ã³ãã³ããå®è¡ããŠã¿ãŠæ£åžžã«çµæãååŸã§ããã°æ£ããèšå®ã§ããŠããŸãã
A
ã®æ¥ç¶èšå®ã§ git ls-remote origin
ã®å®è¡ã«æåãã
次㫠B
ã®ã¢ã«ãŠã³ãæ
å ±ã§æ¥ç¶ãè©Šã¿ãŸãã
# çŸåšã®ãªã¢ãŒããªããžã㪠URL
git remote -v
origin github-A:nikaera/private-repository.git (fetch)
origin github-A:nikaera/private-repository.git (push)
# ãªã¢ãŒããªããžã㪠URL ã github-A:nikaera/private-repository.git ãã
# github-B:nikaera/private-repository.git ã«å€æŽãã
git remote set-url origin github-B:nikaera/private-repository.git
# æ°ãã«èšå®ãããªã¢ãŒããªããžã㪠URL
git remote -v
origin github-B:nikaera/private-repository.git (fetch)
origin github-B:nikaera/private-repository.git (push)
B
ã«ã¯å
ã»ã©ã®ãã©ã€ããŒããªããžããªã®èªã¿åãæš©éãç¡ãç¶æ
ã§ãgit ls-remote origin
ã³ãã³ããå®è¡ããŠã¿ããšå€±æããã¯ãã§ãã
B
ã®æ¥ç¶èšå®ã§ git ls-remote origin
ã®å®è¡ã«å€±æãã
ããã§ä»åŸã¯ git
ã®ãªã¢ãŒããªããžã㪠URL ãäžåºŠæžãæããŠããã ãã§ãããããé©åãªç§å¯éµã§ GitHub èªèšŒããèšå®ãã§ããŸããã
åã« Git ãµãŒãã« SSH æ¥ç¶ããéã®èšå®æ å ±ãšããŠã¯ãäžèšé ç®ãæããŠããã°åé¡ç¡ãã§ããããããä»ã«ãèšå®ããã»ããè¯ãé ç®ããå Žåã«ãã£ãŠã¯èšå®ãå¿ èŠãªé ç®ãååšããŸãã
åºæ¬çã«èšå®ããŠãããæ¹ãè¯ãé ç®
ä»ã«èšå®ããŠãããã»ããè¯ãé ç®ã«ã¯äžèšããããŸãã
# ~/.ssh/config
Host github.com
IdentityFile ~/.ssh/github
User git
IdentitiesOnly yes # IdentityFile ã§æå®ããç§å¯éµã§ã®ã¿èªèšŒãè©Šã¿ã
Compression yes # Git ã§ã®ãã¡ã€ã«è»¢éæã«å§çž®ãã
é ç® | 説æ | å |
---|---|---|
IdentitiesOnly | IdentityFile ã§æå®ããéµãã¡ã€ã«ã§ã®ã¿èªèšŒãè¡ããã©ããæå®ãã | boolean (yes or no ) |
Compression | å§çž®è»¢éãè¡ããã©ããæå®ãã | boolean (yes or no ) |
IdentityFile
ã§æå®ãããã¡ã€ã«ä»¥å€ã§èªèšŒãéã£ãŠããŸãç¶æ³ã ãšãæå³ããã¢ã«ãŠã³ãã§é©åã«èªèšŒãéããŠããªãå¯èœæ§ãåºãŠããŠããŸããŸãã
ãã®ãããç¹å¥ãªçç±ããªããã° IdentitiesOnly
ã«ã¯ yes
ãèšå®ããŠãããã»ããè¯ãã§ãã
IdentitiesOnly
ã no
ã«èšå®ããŠãããš ssh-add
ã§ç»é²ããããŒã®äžãããèªèšŒãè©Šã¿ãããã«ãªããŸãã
ãŸããCompression
ã«ã€ããŠã yes
ã«èšå®ããŠããããšããªã¹ã¹ã¡ããŸããããã°ã©ãã³ã°ãè¡ã£ãŠãããããžã§ã¯ãã§ã¯ãããã¹ããã¡ã€ã«ã®æ°ã倧åãå ããã¯ããªã®ã§ãå§çž®è»¢éãæå¹ã«ããŠãããã»ãããã¡ã€ã«è»¢éã®é床åäžãèŠèŸŒããããã§ãã
ãã ã Compression
ã¯å€§å®¹éã®åäžã®ãã¡ã€ã«ãã¢ãããããŠãããªã©ããŠãå§çž®å¹çã®æªããã¡ã€ã«ãå«ãã§ãããããžã§ã¯ãã®å Žåã¯éã«è»¢éé床ãäœäžããæããããã®ã§èŠæ³šæã§ãã
æ¥ç¶å ã«ãã£ãŠã¯èšå®ãå¿ èŠãªé ç®
æ¥ç¶å ã«å¿ããŠèšå®ããå¿ èŠããããããªé ç®ã«ã¯äžèšããããŸãã
# ~/.ssh/config
Host github.com
IdentityFile ~/.ssh/github
User git
Port 12345 # æ¥ç¶å
ã®ããŒãã 22 以å€ã®å Žåæå®ãã
é ç® | 説æ | å |
---|---|---|
Port | SSH æ¥ç¶æã®ããŒãçªå·ãèšå®ãã | number (ex: 22, 22222, etc.) |
äŸãã°èªåã§çšæãã Git ãªããžããªã«å¯ŸããŠæ¥ç¶ããå ŽåãSSH ã®ããŒããã»ãã¥ãªãã£äžã®çç±çã§ãŠã§ã«ããŠã³ããŒãã® 22
ã§ã¯ãªãå ŽåãããããŸãããã®å Žå㯠Port
ãæ瀺çã«æå®ããããšã§æ¥ç¶æã®ããŒãçªå·ãé©åãªå€ã«èšå®ããŠããå¿
èŠãåºãŠããã§ãããã
ãããã«
ä»å㯠GitHub ãž SSH æ¥ç¶ããéã®äŸãå
ã« ~/.ssh/config
ã®èšå®æ¹æ³ã«ã€ããŠæžããŸããã~/.ssh/config
㧠Host
ã®èšå®ã¯è¡ã£ãŠãããã®ã®ãããã«å¿ã㊠git
ã®ãªã¢ãŒããªããžã㪠URL ãå€æŽãã¹ãå Žåãããããšãæ瀺ããŠããèšäºãå°ãªãã£ãã®ã§æžããŸããã
ãŸããæ¬èšäºã§ã¯ Git æ¥ç¶æã® ~/.ssh/config
ã®èšå®ã«ãã©ãŒã«ã¹ãåœãŠãŸãããã~/.ssh/config
ã«ã€ããŠã¯ãµãŒãã« SSH æ¥ç¶ããŠäœæ¥ããéã«èšå®ããŠãããšè¯ãé
ç®çããããŸãã
~/.ssh/config
ã®åçš®èšå®é
ç®ã«ã€ããŠç解ããŠãããšé »ç¹ã«å®è¡ããã³ãã³ãã®ã³ã¹ãåæžãã§ããŠäŸ¿å©ã§ããç¹ã«ãã¡ãã®èšäºã¯ãšãŠãåèã«ãªããŸããã