๐Ÿฑ Github ์—ฌ๋Ÿฌ ๊ณ„์ •์„ ํ•œ ๋Œ€์˜ ๊ธฐ๊ธฐ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ

bbio3oยท2021๋…„ 4์›” 5์ผ
2

๐Ÿ›ย 

๋ชฉ๋ก ๋ณด๊ธฐ
6/6

์—…๋ฌด์šฉ ๊นƒํ—™ ๊ณ„์ •๊ณผ ๊ฐœ์ธ ๊ณ„์ •์„ ๋ถ„๋ฆฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, ssh-key๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


โœจ 1. ssh ํ‚ค ์ƒ์„ฑ

ํ„ฐ๋ฏธ๋„์—์„œ ์‚ฌ์šฉํ•˜๋ ค๋Š” ๊นƒํ—™ ๊ณ„์ • ์ด๋ฉ”์ผ ๋ณ„๋กœ ํ‚ค๋ฅผ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

$ cd ~ // ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™
$ ssh-keygen -t rsa -C "your_email@youremail.com"

โœจ 2. ssh ํ‚ค ์ถ”๊ฐ€

$ ssh-add ~/.ssh/id_rsa_me
$ ssh-add ~/.ssh/id_rsa_work

โœจ 3. ์ถ”๊ฐ€ ๋œ ํ‚ค ํ™•์ธํ•ด๋ณด๊ธฐ

$ ssh-add -l

โœจ 4. ssh config ํŒŒ์ผ ์ถ”๊ฐ€/์ˆ˜์ •

$ cd ~/.ssh/
$ touch config
$ open ~/.ssh/config

โœจ 5. config ํŒŒ์ผ์— ์•„๋ž˜์™€ ๊ฐ™์ด ์ถ”๊ฐ€

#me account
Host github.com-me // ์ด ๋ถ€๋ถ„ ์ค‘์š”!
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa_me

#work account
Host github.com-work // ์ด ๋ถ€๋ถ„ ์ค‘์š”!
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa_work

๋ฆฌ๋ชจํŠธ ์ €์žฅ์†Œ๋ฅผ ssh ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํด๋ก ํ•˜๊ฒŒ ๋  ๋•Œ -work๋‚˜ -me๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ ํด๋ก ํ•ด์•ผํ•˜๊ธฐ์—
Host๋ฅผ ์ฃผ์˜ ๊นŠ๊ฒŒ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”! IdentityFile์˜ ์ฒ ์ž๋„ ์ž˜ ํ™•์ธํ•ด์ฃผ์„ธ์š”!


โœจ 6. Github ์‚ฌ์ดํŠธ์— ssh key ์ ์šฉํ•ด์ฃผ๊ธฐ

$ pbcopy < ~/.ssh/id_rsa_me.pub // -me ํ‚ค ๋ณต์‚ฌ
$ pbcopy < ~/.ssh/id_rsa_work.pub // -work ํ‚ค ๋ณต์‚ฌ

๊นƒํ—™์—์„œ ๊ณ„์ •์˜ settings๋กœ ์ด๋™ํ•˜์—ฌ ๊ฐ ๊ณ„์ •์— ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋ณต์‚ฌํ•œ sshํ‚ค๋ฅผ cmd(ctrl)+v๋กœ ์ถ”๊ฐ€ํ•ด์ค๋‹ˆ๋‹ค.


โœจ 7. ํ”„๋กœ์ ํŠธ ํด๋ก  ํ•ด๋ณด๊ธฐ

ํด๋ก ํ•  ํ”„๋กœ์ ํŠธ์˜ SSH ๋ณต์‚ฌํ•˜๊ณ 
git@github.com ๋ถ€๋ถ„์„ ์•„๋ž˜์™€ ๊ฐ™์ด github.com-work ๋˜๋Š” github.com-me๋กœ ๋ฐ”๊พธ์–ด ์ฃผ๊ณ  ํด๋ก ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค!

$ git clone git@github.com-me:airbnb/javascript.git

์ƒˆ๋กœ์šด ์›๊ฒฉ์ €์žฅ์†Œ ํด๋ก ํ•  ๋•Œ

git remote add origin git@github.com-work:foo/foo_site.git

๊ธฐ์กด ์›๊ฒฉ ์ €์žฅ์†Œ ์ฃผ์†Œ ๋ฐ”๊ฟ€๋•Œ

git remote set-url origin git@github.com-foo:foo/foo_site.git

โœจ 8. ํ”„๋กœ์ ํŠธ๋งˆ๋‹ค ์œ ์ € ์ด๋ฆ„๊ณผ ์ด๋ฉ”์ผ ๋ณ€๊ฒฝ

$ git config --global user.name // me
$ git config --global user.email // me

$ git config user.name // work
$ git config user.email // work

์ถœ์ฒ˜1 ์ถœ์ฒ˜2

profile
๊ทธ๋ฆผ๋„ ๊ทธ๋ฆฌ๋Š” ๊ฐœ๋ฐœ์ž ๐ŸŽจ๐Ÿ‘ฉโ€๐Ÿ’ป

0๊ฐœ์˜ ๋Œ“๊ธ€