HTTPSã¯ããŒã³ãããã£ãããšããªãã£ãããªããžèŽãSSHã¯ããŒã³ç·ãŸãšãð
SSH Keysã®çºè¡ïœãªããžããªã®ã¯ããŒã³ãŸã§ãGitHubãäŸã«ãã£ãŠã¿ããïŒ
åæ
- Windows10 ãŸã㯠macOS Monterey 12.0.1 æ³å®
- Windowsã®å Žåã¯ã¹ã¿ã³ããŒããµã€ãºã»ãã«ãµã€ãºãªã©ã®ããŒããŒãïŒInsertããŒã䜿ãããã®ïŒ
- 管çè ã¢ã«ãŠã³ã
- Gitã®ãŠãŒã¶èšå®ãé©åã«èšå®ãããŠããïŒæ¬èšäºã®å·¥çšããã¹ãŠçµããåŸã«èšå®ããŠãOKïŒ
git config --global user.name
git config --global user.email
Package managerãå
¥ããã
ãœãããŠã§ã¢ã€ã³ã¹ããŒã«ã楜ã«ãªãã®ã§ããããããWindowsãªãChocolateyãmacOSãªãHomebrewãå
¥ããŠãããŸãããïŒð
-
Chocolateyã®ã€ã³ã¹ããŒã«æ¹æ³ -
choco
ã³ãã³ãã䜿ããããã«ãªã -
Homebrewã®ã€ã³ã¹ããŒã«æ¹æ³ -
brew
ã³ãã³ãã䜿ããããã«ãªã
â» ããããå©çšããªãå Žåã§ããä»»æã®æ¹æ³ã§å¿
èŠãªãœãããŠã§ã¢ãã€ã³ã¹ããŒã«ã§ããŸã
â» ããããã®èšäºã®choco
ãbrew
以å€ã®å
容ãèŠãŠããã ãããšããããã§ãâº
1. ç°å¢ãæŽããã
åŸã«ç¶ãè¡šã«æ²¿ã£ãŠããã®èšäºã§å¿ èŠãªã¢ããªã±ãŒã·ã§ã³ãã€ã³ã¹ããŒã«ãããŠããã確èªããŸãã
ãŸãã¯ã·ã§ã«ãéããŸãããã
- WindowsïŒPowerShell
- macOSïŒã¿ãŒããã«ãiTerm2ãªã©
è¡šã®è¡ããšã«ã次ã®ã¹ããããç¹°ãè¿ããŠãã ããã
- ã·ã§ã«ã«ãããŒãžã§ã³ã®ç¢ºèªæ¹æ³ããå ¥åãEnterããŒãæŒã
- ããŒãžã§ã³ãè¿ã£ãŠããã確èªãã
確èªã§ããªãïŒãWindowsçšããŸãã¯ãmacOSçšãã®ã³ãã³ããå®è¡ããŠã2ãã«æ»ã
確èªã§ããïŒ æ¬¡ã®ã¢ããªãã確èªãã ãã
ã³ãã³ãã¯å€§æåå°æåãåºå¥ããŸã
ã¢ããªã±ãŒã·ã§ã³ | ããŒãžã§ã³ã®ç¢ºèªæ¹æ³ | Windowsçš | macOSçš |
---|---|---|---|
Git | git --version |
choco install git.install -y |
brew install git |
OpenSSH | ssh -V |
choco install openssh -y |
brew install openssh |
vim |
vi --version ïŒã¡ãã£ãšé·ãïŒ |
choco install vim -y |
察å¿äžèŠ1 |
ãWindowsã®ã¿ãSSHãæå¹ã«ãã
管çè
æš©éã®PowerShellã§ä»¥äžã®ã³ãã³ããå®è¡ããŠãã ããã
Set-Service -Name ssh-agent -StartupType Manual
Start-Service ssh-agent
2. SSH keysãçºè¡ããã
次ã®ã³ãã³ãã1è¡ãã€ãã·ã§ã«ã§å®è¡ããŸãã
cd ~ # ãŠãŒã¶ã«ãŒããã£ã¬ã¯ããªã«ç§»åããŸãïŒC:/User/ã¢ã«ãŠã³ãåïŒ
Get-Location # çŸåšã®ãã£ã¬ã¯ããªã確èªããŸã
ls # çŸåšã®ãã£ã¬ã¯ããªã®äžèº«ã確èªããŸã
cd ~ # ãŠãŒã¶ã«ãŒããã£ã¬ã¯ããªã«ç§»åããŸãïŒ/User/ã¢ã«ãŠã³ãåïŒ
pwd # çŸåšã®ãã£ã¬ã¯ããªã確èªããŸã
ls -l # çŸåšã®ãã£ã¬ã¯ããªã®äžèº«ã確èªããŸã
ls
ã³ãã³ãã§.ssh
ãšãããã©ã«ãã確èªã§ããªãã£ãå Žåã¯ãmkdir
ã³ãã³ãã§ãã©ã«ããäœæããŸãã
mkdir .ssh
.ssh/
ãã£ã¬ã¯ããªã«ç§»åããŠãSSH keysãçºè¡ããŸãããã
cd ~/.ssh # ãŠãŒã¶ã«ãŒã/.ssh/ ãšãããã£ã¬ã¯ããªã«ç§»å
ssh-keygen
ã³ãã³ãã䜿ã£ãŠç§å¯éµãšå
¬ééµïŒSSH keysïŒãäœæããŸãã
ssh-keygen -t ed25519 -C "ããªãã®ã¡ãŒã«ã¢ãã¬ã¹" # GitHubã«ç»é²ããŠããã¡ãŒã«ã¢ãã¬ã¹ã«çœ®ãæããŠãã ãã
ssh-keygen
ã§ãªã«ããŠãã®ïŒ
ç§å¯éµãšå
¬ééµãçæããŠããŸãã
-t
ã¯æå·åæ¹åŒãæå®ããããã®ãªãã·ã§ã³ã§ãed25519
ãšããã®ã¯ãã€ãã€ããªæå·æ¹åŒã®ååã§ãã
-C
ã¯ãã®SSH keysã«å«ããã³ã¡ã³ãã§ãã
å ¥åãããšã次ã®ãããªã³ã¡ã³ããè¿ã£ãŠããŸãã
Generating public/private ed25519 key pair.
Enter file in which to save the key (***************************************):
ãäœãŠãã¡ã€ã«åã§äœãïŒããšèãããŠããã®ã§ãããã§ã¯ãgithub_rsaããšå
¥åããŸãããã
ãã®ããšEnterããŒãæŒããšããã¹ã¯ãŒãã決ããŠãã ãããšèšãããŸãã
GitHub以å€ã®ãµãŒãã¹çšã«SSH keysãçºè¡ããå Žå
ãã®èšäºã®ãgithub_rsaãããã¹ãŠããµãŒãã¹å_rsaãã«çœ®ãæããŠããã ãããšã§ãGitHub以å€ã®ããã®éµãçºè¡ã§ããŸãã
ã·ã§ã«ã§ãã¹ã¯ãŒããå
¥åãããšãã®è«žæ³šæ
ããŒãå
¥åããŠãæåãå
¥åãããªãããã«èŠããŠããŸãããå®éã«ã¯å
¥åããããšãã§ããŠããŸãã
ããã¯ãäœæåå
¥åããŠããã®ããä»äººããèŠãèŠãããªãããã«ããããã®ã»ãã¥ãªãã£å¯Ÿçã§ãã
ãEnter same passphrase againïŒç¢ºèªçšã«åããã¹ã¯ãŒããå ¥åããŠãïŒããšããããã®ã§åæ§ã«å ¥åããŸãã
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
ãã¹ã¯ãŒããããŸãå ¥åã§ãããšã次ã®ãããªãã°ãåºåãããŸãã
Your identification has been saved in github_rsa.
Your public key has been saved in github_rsa.pub.
The key fingerprint is:
SHA256:****************************************** ããªãã®ã¡ãŒã«ã¢ãã¬ã¹
The key's randomart image is:
+--[ED25519 256]--+
| |
| |
| |
| |
| :^) |
| |
| |
| |
| |
+----[SHA256]-----+
次ã®ã³ãã³ããå®è¡ããŠãgithub_rsa
ããã³github_rsa.pub
ãã¡ã€ã«ãçæãããŠããã®ã確èªããŸãã
ls # çŸåšã®ãã£ã¬ã¯ããªã®äžèº«ã確èªããŸã
ls -l # çŸåšã®ãã£ã¬ã¯ããªã®äžèº«ã確èªããŸã
ããšã§äœ¿ãããããŸã ã·ã§ã«ã¯éããªãã§ãã ããã
ããã§ã²ãšæ®µèœ
ãgithub_rsaãããã³ãgithub_rsa.pubããšãããã¡ã€ã«ã.ssh
ãã£ã¬ã¯ããªã«çæãããŠããªãå ŽåãäœããééããŠããŸãã
ã§ããŠããªãå Žåå
ã«é²ãŸãªãã§ãæåããæé ã確èªããŠãã ããã
SSH Keysã¯ã ãã«ãæããŠã¯ãããŸãã
ããã§çæãããã¡ã€ã«ã誰ãã«éã£ãããäžèº«ã誰ãã«æãããããªãã§ãã ããã
3. ããŸããªããããŠããã
SSHã®èšå®ãã¡ã€ã«ã«æ¬¡ã®å
容ãè¿œèšããŸãã
ã¡ãã£ãšãããããã§ãããæé éããã£ãŠã¿ãŸãããã
以äžã®å 容ããã¹ãŠã³ããŒããŠãããŠãã ãã23ïŒããŒã¹ãã¯ããªãïŒã
Host *
IgnoreUnknown AddKeysToAgent,UseKeychain
AddKeysToAgent yes
UseKeychain yes
Host github.com
HostName ssh.github.com
Port 443
User git
IdentityFile ~/.ssh/github_rsa
-
vi ~/.ssh/config
ãã·ã§ã«ã§å®è¡ããïŒvimãšãã£ã¿ã§config
ãã¡ã€ã«ãéãïŒ - äœãæžãããŠããªãã¯ããªã®ã§ãå
é ã«è²Œãä»ããïŒäœãããå Žåã¯å
é ã«ïŒ
Windowsã®å Žåã¯ShiftïŒInsertããŒãå ¥åããïŒvimãšãã£ã¿ã§ã®è²Œãä»ãïŒ -
:wq
ãšå ¥åããïŒvimãšãã£ã¿ã§ã®ä¿åããŠçµäºïŒ
貌ãä»ããééããïŒä¿®æ£ããããã©æåãæ¶ããªãïŒ
i ããŒãå
¥åããŠç·šéã¢ãŒãã«åãæ¿ããåŸã«ä¿®æ£ããŠãã ããã
ä¿®æ£ãçµãã£ãåŸãESCããŒã§ããŒãã«ã¢ãŒãã«æ»ããŸãã®ã§ãæé 3ãå®æœããŠãã ããã
vi
ã³ãã³ãã®åŸã§ããããããªããªã£ãïŒãŸãã¯æåããããçŽãããïŒ
å·éã«ESCããŒãæ°åæŒããŠã:q!
ãšå
¥åããåŸã«EnterããŒãæŒããŸãããã
vi
ã³ãã³ãã以å€ã®ãã·ãŒã³ã§ããããããªããªã£ãïŒ
å·éã«CtrlïŒCããŒãæŒããŸãããã
4. GitHubããã«å ¬ééµãæž¡ãã
ãªãGitHubããã«å
¬ééµãæž¡ãã®ïŒ
ä»åäœã£ãSSH keysã®ãã¡ããgithub_rsaããç§å¯éµããgithub_rsa.pubããå
¬ééµãšåŒã°ããŠããŸãã
å
¬ééµãšã¯æ¥ç¶å
ã«æž¡ãå京é ã§ããããããããæ
å ±ã®å庫ãã®æžç· ãã«äœ¿ãããŸãïŒæå·åçšïŒã
ç§å¯éµãšã¯ããã®å京é ãéããããå¯äžã®éµã§ãïŒè€ååçšïŒã
ãç§ã®ããŒã¿ãæ¹ãããããªãããã«ãæžãæããæš©éã¯ãã®å京é ã§ãã£ããæžç· ãããŠãïŒããšãGitHubãããšçŽæããããã«å ¬ééµãæž¡ããªããã°ãªããŸããã
å
ã»ã©ã®ã·ã§ã«å
ã§ã次ã®ã³ãã³ããå
¥åããŠå
¬ééµïŒgithub_rsa.pub
ãã¡ã€ã«ïŒã®äžèº«ã確èªããŸãã
ã·ã§ã«ãéããŠããŸã£ã人ã¯ã*.pub
ãã¡ã€ã«ã¯ããã¹ããšãã£ã¿ãªã©ã§éããŠãOKã§ãã
cat github_rsa.pub # Windowsã§ã¯vimãã€ã³ã¹ããŒã«ãããŠããªããšäœ¿ããªããéåžžã¯`type github_rsa.pub`
ãããšã次ã®ãããªæååãè¿ã£ãŠããŸãããããå ¬ééµã§ãã
ssh-ed25519 ******************************************************************* ããªãã®ã¡ãŒã«ã¢ãã¬ã¹
ãããéžæããŠã³ããŒããŸãã
ããŸãã³ããŒã§ããªãå Žåã¯æ¬¡ã®æ¹æ³ãå®æœããŠã¿ãŠãã ããã
Windowsã®å ŽåïŒã©ã¡ããïŒ
- ãå³ã¯ãªãã¯ãâããã¹ãŠéžæãâã·ã§ã«å ã®ã©ãã§ãããã®ã§ã¯ãªãã¯â察象åæãéžæããŠãCtrlïŒCããŒã
- ããã¹ããšãã£ã¿ã§éããŠã³ããŒãã
macOSã®å Žå
pbcopy < github_rsa.pub # .sshãã£ã¬ã¯ããªã«ããªãå Žå㯠pbcopy < ~/.ssh/github.pub
ã³ããŒã§ããããGitHubããã«å ¬ééµãæž¡ãã«è¡ããŸãããïŒ
- GitHubã«ãã°ã€ã³ãã
- SettingsããŒãžããSSH and GPG keysããŒãžãéã
- New SSH Keyãã¿ã³ãã¯ãªãã¯ãã
- ããã¹ããã£ãŒã«ããTitleãã«ä»»æã®æååãå ¥åããïŒä»ã䜿ãã®PCã®ååãããšãã°ãäœä»£ç®MacBook Proããããšãã§ãOKïŒ
- ããã¹ããã£ãŒã«ããKeyãã«ã³ããŒããå ¬ééµã貌ãä»ãã
- Add SSH keyãã¿ã³ãã¯ãªãã¯ãã
ç§å¯éµã®æµåºã«ã泚æïŒ
å
¬ééµã¯ãããæµåºããŠãéµããããïŒæå·åããïŒã ãã«ãã䜿ããŸããã
ãŸããå
¬ééµããç§å¯éµãç¹å®ããã®ã¯äžå¯èœã ãšããããŠããŸãã
äžæ¹ã§ãããç§å¯éµã誰ãã«æž¡ããŠããŸã£ãå Žåããã¢ã«ãªã£ãŠããç§å¯éµã§æå·åãããæ å ±ãååããããããéãããªãã§ã¯ãªã誰ãããããªãã®ãµããããŠããªãã®å庫ã«å ¥ã蟌ãã§ããŠããŸããŸãã
äžãäžæµåºããŠããŸã£ãå Žåã¯ãããã«ãã®ãã¢ã®éµã®å©çšãåæ¢ïŒåé€ïŒããŠãæ°ããéµãäœãçŽãå¿ èŠããããŸãã
5. æ¥ç¶ã§ããã確èªããŠã¿ãã
ç»é²ãã§ããããç¡äºã«SSHæ¥ç¶ãã§ãããã©ãããè©ŠããŠã¿ãŸãã
ssh-add github_rsa
Error connecting to agent: No such file or directory ã«ãªã£ã¡ããïŒ
ssh-agentãç¡å¹ã«ãªã£ãŠããŸãã
ãSSHãæå¹ã«ããããåç
§ããŠãã³ãã³ããå®è¡ããŠããå床ssh-add
ããŠã¿ãŠãã ããã
ãããšã次ã®ãããªæååãè¿ã£ãŠããŸãã
Enter passphrase for github_rsa:
SSH keysãçæïŒssh-keygen
ïŒãããšãã«èšå®ãããã¹ã¯ãŒããå
¥åããŠãã ããã
ãã¹ã¯ãŒããæ£ãããã°ã次ã®ãããªããã¹ãã衚瀺ãããŸãã
Identity added: github_rsa (ããªãã®ã¡ãŒã«ã¢ãã¬ã¹)
ãããŸã§ã§ããããæ©éæ¥ç¶ãã¹ãã§ãã
ssh -T git@github.com # ãµãŒãã¹ã«ãã£ãŠç°ãªããŸãã e.g. git@bitbucket.org
次ã®ããã«ãfingerprintããæ£ãããå°ããããŸãã
The authenticity of host 'github.com (XXX.XXX.XXX.XXX)' can't be established.
ED25519 key fingerprint is SHA256:*******************************************.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
ãã®å Žåã¯ãGitHubã®SSH and GPG keysããŒãžãéããŠãfingerprintãäžèŽããã確èªããŠãã ããã
æ£ãããªããŠããyesãã§æ¥ç¶ã§ããããšãããããã§ãïŒèª¿æ»äžïŒ
æ£ãããã°yes
ãšå
¥åããŠEnterããŒãæŒäžããŸãã
æ¥ç¶ã«æåãããšã次ã®ãããªããã¹ãã衚瀺ãããŸãã
Hi ããªãã®åå! You've successfully authenticated, but GitHub does not provide shell access.
ããšããäžæ¯ïŒ
ããã§æ¥ç¶æåã®ããã¹ãã衚瀺ãããªãå Žåå ŽåãäœããééããŠããŸãã
å
ã«é²ãŸãã«æåããæé ã確èªããŠãã ããã
6. ã¯ããŒã³ããŠã¿ãã
ã奜ããªGitã¯ã©ã€ã¢ã³ãã§ãªããžããªãSSHã§ã¯ããŒã³ããŠã¿ããïŒ
æ®æ®µGUIã䜿ã£ãŠããïŒãšããæ¹ãž
GUIã§ã®SSHã¯ããŒã³ã¯ãåçš®GUIã®ããã¥ã¡ã³ããåç
§ããŠãã ããã
以äžã§SSHæ¥ç¶ã§ã®ã¯ããŒã³æºåã¯ãããŸãã§ãããã€ããããŸã§ããïŒ
ããŒã«ã«ãªããžããªã眮ããããã£ã¬ã¯ããªã«ã·ã§ã«ã§ç§»åããŠãGitHubã®å¥œããªãªããžããªã®SSHãã¹ãã³ããŒããŠããŸãã
heppokofrontend/heppokofrontendã®ãªããžããªãSSHã¯ããŒã³ããŠããäŸãèŠãŠã¿ãŸãããã
cd ~
git clone git@github.com:heppokofrontend/heppokofrontend.git # 泚æïŒèªåã®ãªããžããªã§ãªããã°`git push`ã§ããªã
cd heppokofrontend
ls # ãªããžããªã®äžèº«ã確èªã§ããŸã
URLã«ã泚æ
ééããŠãhttpãã§å§ãŸãURLã§ã¯ããŒã³ããŠããŸããšããããŸã§ã®å·¥çšã®æå³ããªããªã£ãŠããŸããŸãã
å¿
ãSSHã®ãã¹ã䜿ã£ãŠã¯ããŒã³ããŸãããã
ãã¹ã¯ãŒããèãããå Žåã¯ãå
¥åããŠããEnterããŒãæŒããšç¡äºã«SSHæ¥ç¶ã§ã¯ããŒã³ãå§ãŸããŸãã
ããŒã«ã«ãªããžããªãèœã¡ãŠããŠããã¯ããªã®ã§ãããšã¯èªç±ã«éçºããŸãããïŒ
ãã€ããããŸã§ããïŒð¥³ð¥
SSHæ¥ç¶ã䜿ããµãŒãã¹ã¯ã»ãšãã©åãããæ¹ïŒ
SSH Keysã䜿ãGitHubã®ãããªãµãŒãã¹ã¯ãåºæ¬çã«å
¬ééµãç»é²ããããã®ã¡ãã¥ãŒãã©ããã«ãããŸãã
SSH Keysãçºè¡ãããããŸãã¯å
¬ééµããµãŒãã¹ã«æž¡ããŸãã
ããšã¯ã3. ããŸããªããããŠããããã®ç« ã§è¡ã£ããã©ã®ãã¡ã€ã³ã«ã¯ã©ã®ç§å¯éµã䜿ããã®èšè¿°ã~/.ssh/config
ã«è¿œèšããŠãããã°SSHæ¥ç¶ãå©çšã§ããŸãã
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_rsa
-
macOSã¯ããã©ã«ãã§vimã䜿ãã â©
-
UserKeychainã¯macOSåãã®èšè¿°ã§ãäœåºŠããã¹ã¯ãŒãã®å ¥åãããªããŠããããªãæ¹æ³ã§ãã â©
-
ããã¯Port 22ã䜿ããªãæ¹æ³ã§ããéåžžã¯HostNameã¯ãgithub.comãPortã¯çç¥ïŒããã©ã«ãã§22ïŒããŸãã â©