[Git] SSH๋กœ GitHub Repository Cloneํ•˜๊ธฐ ๐Ÿ”‘

์„œ์ฟ ยท2024๋…„ 5์›” 28์ผ
1

Git-ํ˜‘์—…

๋ชฉ๋ก ๋ณด๊ธฐ
7/8
post-thumbnail
post-custom-banner

SSH๋กœ GitHub Repository Cloneํ•˜๋Š” ๋ฐฉ๋ฒ•

์˜ค๋Š˜์€ SSH๋ฅผ ์ด์šฉํ•ด GitHub ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ํด๋ก (clone)ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹คโญ GitHub/GitLab์„ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋ฉด ๋งค๋ฒˆ ์ƒ๊ธฐ๋Š” ์ธ์ฆ ๋ฌธ์ œ!!! ๋„ˆ๋ฌด ๋จธ๋ฆฌ ์•„ํ”„์‹œ์ฃ ...! ๊ทธ๋ž˜์„œ ์ €๋Š” ์ด์ œ SSH๋ฅผ ์ด์šฉํ•ด์„œ ๋ณด์•ˆ๋„ ์ฑ™๊ธฐ๊ณ , ํ•œ๋ฒˆ์— ์ธ์ฆ๋„ ํ•  ์ˆ˜ ์žˆ๋Š” ํŽธ์˜์„ฑ๋„ ์ฑ™๊ฒจ๊ฐ€๋ ค๊ณ ์š” ๐Ÿ˜Ž

SSH๋ฅผ ์ด์šฉํ•ด GitHub ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ํด๋ก ํ•˜๋ฉด ๋งค๋ฒˆ ์ธ์ฆ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค. ํ•œ ๋ฒˆ SSH ํ‚ค๋ฅผ ์„ค์ •ํ•˜๊ณ  ๋‚˜๋ฉด, ์ดํ›„์—๋Š” ์ž๋™์œผ๋กœ ์ธ์ฆ์ด ์ด๋ฃจ์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์— Git ์ž‘์—…์„ ๋ณด๋‹ค ํŽธ๋ฆฌํ•˜๊ฒŒ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฒˆ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ์—์„œ๋Š” SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ด๋ฅผ GitHub์— ๋“ฑ๋กํ•œ ํ›„, ์ด๋ฅผ ์ด์šฉํ•ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ํด๋ก ํ•˜๋Š” ์ „์ฒด ๊ณผ์ •์„ ๋‹ค๋ฃน๋‹ˆ๋‹ค. Ubuntu์™€ Windows ํ™˜๊ฒฝ์—์„œ์˜ SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ณผ์ •์„ ๊ฐ๊ฐ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

1. SSH ํ‚ค ์ƒ์„ฑํ•˜๊ธฐ

SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด์™€ ์˜ต์…˜๋“ค์— ๋Œ€ํ•ด ๋จผ์ € ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

  • ssh-keygen: SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค.
  • -t rsa: ํ‚ค ํƒ€์ž…์„ RSA๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. RSA๋Š” ํ˜„์žฌ ๊ฐ€์žฅ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ๊ณต๊ฐœํ‚ค ์•”ํ˜ธํ™” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
  • -b 4096: ํ‚ค์˜ ๋น„ํŠธ ์ˆ˜๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. 4096 ๋น„ํŠธ๋Š” ๋งค์šฐ ๊ฐ•๋ ฅํ•œ ๋ณด์•ˆ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • -C "your_email@example.com": ํ‚ค์— ์ฃผ์„(Comment)์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ๋ณดํ†ต ์ž์‹ ์˜ ์ด๋ฉ”์ผ ์ฃผ์†Œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

Ubuntu์—์„œ SSH ํ‚ค ์ƒ์„ฑ

  1. SSH ํ‚ค ์ƒ์„ฑ ๋ช…๋ น์–ด ์‹คํ–‰

    ํ„ฐ๋ฏธ๋„์„ ์—ด๊ณ  ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ช…๋ น์–ด๋Š” ์ƒˆ๋กœ์šด SSH ํ‚ค ์Œ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/id_rsa_github

    ์—ฌ๊ธฐ์„œ -f ~/.ssh/id_rsa_github๋Š” ์ƒ์„ฑ๋œ ํ‚ค ํŒŒ์ผ์˜ ์ด๋ฆ„์„ id_rsa_github๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

  2. ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ

    ํ”„๋กฌํ”„ํŠธ๊ฐ€ ๋‚˜ํƒ€๋‚˜๋ฉด ํ•„์š”์— ๋”ฐ๋ผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์„ค์ •ํ•˜์ง€ ์•Š์œผ๋ ค๋ฉด Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

    Enter passphrase (empty for no passphrase): [Type a passphrase]
    Enter same passphrase again: [Type passphrase again]
  3. ์ƒ์„ฑ๋œ SSH ํ‚ค ํ™•์ธ

    ๋‹ค์Œ ๋ช…๋ น์–ด๋กœ SSH ํ‚ค๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

    cat ~/.ssh/id_rsa_github.pub

Windows์—์„œ SSH ํ‚ค ์ƒ์„ฑ

  1. Git Bash ์„ค์น˜ ๋ฐ ์‹คํ–‰

    Windows์—์„œ๋Š” Git Bash๋ฅผ ์ด์šฉํ•ด SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. Git Bash๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  2. SSH ํ‚ค ์ƒ์„ฑ ๋ช…๋ น์–ด ์‹คํ–‰

    Git Bash์—์„œ ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/id_rsa
  3. ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ

    ํ”„๋กฌํ”„ํŠธ๊ฐ€ ๋‚˜ํƒ€๋‚˜๋ฉด ํ•„์š”์— ๋”ฐ๋ผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์„ค์ •ํ•˜์ง€ ์•Š์œผ๋ ค๋ฉด Enter ํ‚ค๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

    Enter passphrase (empty for no passphrase): [Type a passphrase]
    Enter same passphrase again: [Type passphrase again]
  4. ์ƒ์„ฑ๋œ SSH ํ‚ค ํ™•์ธ

    ๋‹ค์Œ ๋ช…๋ น์–ด๋กœ SSH ํ‚ค๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

    cat ~/.ssh/id_rsa.pub

2. SSH ํ‚ค GitHub์— ๋“ฑ๋กํ•˜๊ธฐ

  1. GitHub ๋กœ๊ทธ์ธ ๋ฐ ์„ค์ • ํŽ˜์ด์ง€ ์ด๋™

    GitHub์— ๋กœ๊ทธ์ธํ•œ ํ›„, ์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ ํ”„๋กœํ•„ ์•„์ด์ฝ˜์„ ํด๋ฆญํ•˜๊ณ  Settings๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  2. SSH ๋ฐ GPG ํ‚ค ๋ฉ”๋‰ด ์„ ํƒ

    ์™ผ์ชฝ ๋ฉ”๋‰ด์—์„œ SSH and GPG keys๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  3. ์ƒˆ SSH ํ‚ค ์ถ”๊ฐ€

    New SSH key ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. Title์—๋Š” ํ‚ค์˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ , Key์—๋Š” ์•ž์„œ ์ƒ์„ฑํ•œ SSH ํ‚ค๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ ๋ถ™์—ฌ๋„ฃ์Šต๋‹ˆ๋‹ค.

    # Ubuntu ๋˜๋Š” Windows์—์„œ ์‹คํ–‰
    cat ~/.ssh/id_rsa.pub

    ํ‚ค ๋‚ด์šฉ์„ ๋ณต์‚ฌํ•œ ํ›„ GitHub์˜ Key ํ•„๋“œ์— ๋ถ™์—ฌ๋„ฃ๊ณ  Add SSH key ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

3. SSH๋ฅผ ์ด์šฉํ•œ GitHub Repository ํด๋ก ํ•˜๊ธฐ

  1. ๋ ˆํฌ์ง€ํ† ๋ฆฌ URL ๋ณต์‚ฌ

    ํด๋ก ํ•˜๊ณ ์ž ํ•˜๋Š” GitHub ๋ ˆํฌ์ง€ํ† ๋ฆฌ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜์—ฌ Code ๋ฒ„ํŠผ์„ ํด๋ฆญํ•œ ํ›„ SSH๋ฅผ ์„ ํƒํ•˜๊ณ  URL์„ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

  2. ๋ ˆํฌ์ง€ํ† ๋ฆฌ ํด๋ก  ๋ช…๋ น์–ด ์‹คํ–‰

    ํ„ฐ๋ฏธ๋„(Git Bash)์—์„œ ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ํด๋ก ํ•ฉ๋‹ˆ๋‹ค.

    git clone git@github.com:username/repository.git

    username๊ณผ repository๋Š” ๋ณต์‚ฌํ•œ URL์— ๋งž๊ฒŒ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

๊ฒฐ๋ก 

์ด์ œ SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  GitHub์— ๋“ฑ๋กํ•œ ํ›„, SSH๋ฅผ ์ด์šฉํ•ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ํด๋ก ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ตํ˜”์Šต๋‹ˆ๋‹ค. ์ด ๊ณผ์ •์„ ํ†ตํ•ด ํ•œ ๋ฒˆ ์„ค์ • ํ›„์—๋Š” ๋งค๋ฒˆ ์ธ์ฆ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•  ํ•„์š” ์—†์ด GitHub์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์ž‘์—… ํšจ์œจ์„ ํฌ๊ฒŒ ๋†’์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

SSH๋ฅผ ์ด์šฉํ•œ ์ ‘๊ทผ์€ ๋ณด์•ˆ์„ฑ์ด ๋†’๊ณ  ํŽธ๋ฆฌํ•˜๋ฏ€๋กœ, ํŠนํžˆ ๊ฐœ์ธ ์ปดํ“จํ„ฐ์—์„œ ์ž‘์—…ํ•  ๋•Œ ๋งค์šฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ถ”๊ฐ€์ ์œผ๋กœ Credential Helper๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ HTTP(S) ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ•  ๋•Œ๋„ ์ธ์ฆ ์ •๋ณด๋ฅผ ์‰ฝ๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ค๋Š˜๋„ ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๋‹ค์Œ ํฌ์ŠคํŠธ๋Š” ์š” ์œ„์— Credential Helper์— ๋Œ€ํ•ด์„œ ์„ค๋ช…ํ•˜๋Š” ๊ธ€๋กœ ์ฐพ์•„๋ต™๊ฒ ์Šต๋‹ˆ๋‹ค!

profile
Always be passionate โœจ
post-custom-banner

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