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

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

Git-ํ˜‘์—…

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

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

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

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

SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•œ ํ›„ GitHub์— ๋“ฑ๋กํ•˜๋ฉด ๋งค๋ฒˆ ์ธ์ฆ ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” Windows์™€ Ubuntu ํ™˜๊ฒฝ์—์„œ์˜ SSH ํ‚ค ์ƒ์„ฑ ๊ณผ์ •์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

1. SSH ํ‚ค ์ƒ์„ฑ - ๊ณตํ†ต ๋ช…๋ น์–ด

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

  • ssh-keygen: SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค.

  • -t rsa: ํ‚ค ํƒ€์ž…์„ RSA๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

  • -b 4096: ํ‚ค์˜ ๋น„ํŠธ ์ˆ˜๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. 4096 ๋น„ํŠธ๋Š” ๊ฐ•๋ ฅํ•œ ๋ณด์•ˆ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  • -C \"your_email@example.com\": ํ‚ค์— ์ฃผ์„(Comment)์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    • ๋ณดํ†ต ์ž์‹ ์˜ ์ด๋ฉ”์ผ ์ฃผ์†Œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

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

  1. Git Bash ์‹คํ–‰:

    • Windows์—์„œ๋Š” Git Bash๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  2. SSH ํ‚ค ์ƒ์„ฑ ๋ช…๋ น์–ด ์‹คํ–‰:

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/id_rsa_github
    • -f ~/.ssh/id_rsa_github: ํ‚ค ํŒŒ์ผ ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    • ์˜ˆ์‹œ

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

๐Ÿค” ์–ด? Powershell๋กœ ํ•˜๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ ๊ฐ™์•„์š”!! ๋งŒ์•ฝ Powershell๋กœ ์‹คํ–‰ํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ,

  • PowerShell์—์„œ ๋ฐœ์ƒํ•œ ์˜ค๋ฅ˜๋Š” ~/.ssh/id_rsa_github ๊ฒฝ๋กœ๋ฅผ Windows PowerShell์ด ์ดํ•ดํ•˜์ง€ ๋ชปํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
  • Windows์—์„œ๋Š” ~๊ฐ€ ์‚ฌ์šฉ์ž์˜ ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋‚˜ํƒ€๋‚ด์ง€๋งŒ, PowerShell์—์„œ๋Š” ์ด๋ฅผ ์ง์ ‘์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๊ฒฝ๋กœ๋ฅผ Windows์˜ ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋กœ ์ง€์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    1. SSH ํ‚ค ์ƒ์„ฑ ์‹œ ๊ฒฝ๋กœ๋ฅผ ์ˆ˜์ •:
      • ์•„๋ž˜์™€ ๊ฐ™์ด ~/.ssh ๋Œ€์‹  Windows์˜ ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค:
      ssh-keygen -t rsa -b 4096 -C "jasuchung@gmail.com" -f $HOME\\.ssh\\id_rsa_github
      • $HOME์€ PowerShell์—์„œ ์‚ฌ์šฉ์ž์˜ ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
      • Windows์—์„œ๋Š” ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ๋ณดํ†ต C:\\Users\\<์‚ฌ์šฉ์ž ์ด๋ฆ„>๋กœ ์„ค์ •๋ฉ๋‹ˆ๋‹ค.
    2. ~/.ssh ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ ๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑ:
      • ~/.ssh ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์•„์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. PowerShell์—์„œ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜์„ธ์š”:
        mkdir $HOME\\.ssh
    3. ์ƒ์„ฑ๋œ ํ‚ค ํ™•์ธ:
      • ํ‚ค ์ƒ์„ฑ ํ›„, ๊ณต๊ฐœ ํ‚ค๋ฅผ ํ™•์ธํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์„ธ์š”:
        cat $HOME\\.ssh\\id_rsa_github.pub
  1. ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ:
    • ํ”„๋กฌํ”„ํŠธ๊ฐ€ ๋‚˜ํƒ€๋‚˜๋ฉด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์„ค์ •ํ•˜๊ฑฐ๋‚˜ Enter ํ‚ค๋ฅผ ๋ˆŒ๋Ÿฌ ๋น„๋ฐ€๋ฒˆํ˜ธ ์—†์ด ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  1. ์ƒ์„ฑ๋œ SSH ํ‚ค ํ™•์ธ:

    cat ~/.ssh/id_rsa_github.pub
    • ์ถœ๋ ฅ๋œ ํ‚ค๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ GitHub์— ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.

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

  1. ํ„ฐ๋ฏธ๋„ ์‹คํ–‰:

    • Ubuntu์—์„œ๋Š” ํ„ฐ๋ฏธ๋„์„ ์—ด์–ด ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  2. SSH ํ‚ค ์ƒ์„ฑ ๋ช…๋ น์–ด ์‹คํ–‰:

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/id_rsa_github
    • -f ~/.ssh/id_rsa_github: ํ‚ค ํŒŒ์ผ ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

    • ์˜ˆ์‹œ

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

    • ํ”„๋กฌํ”„ํŠธ๊ฐ€ ๋‚˜ํƒ€๋‚˜๋ฉด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์„ค์ •ํ•˜๊ฑฐ๋‚˜ Enter ํ‚ค๋ฅผ ๋ˆŒ๋Ÿฌ ๋น„๋ฐ€๋ฒˆํ˜ธ ์—†์ด ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  4. ์ƒ์„ฑ๋œ SSH ํ‚ค ํ™•์ธ:

    cat ~/.ssh/id_rsa_github.pub
    • ์ถœ๋ ฅ๋œ ํ‚ค๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ GitHub์— ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.

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

  1. GitHub ๋กœ๊ทธ์ธ ๋ฐ ์„ค์ • ํŽ˜์ด์ง€ ์ด๋™:
    • GitHub์— ๋กœ๊ทธ์ธํ•œ ํ›„ ์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ ํ”„๋กœํ•„ ์•„์ด์ฝ˜์„ ํด๋ฆญํ•˜์—ฌ Settings๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

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

  1. ์ƒˆ SSH ํ‚ค ์ถ”๊ฐ€:
    • New SSH key ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  1. ํ•„์š” ์ •๋ณด ์ž…๋ ฅ
    • Title์—๋Š” ํ‚ค์˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ , Key ํ•„๋“œ์—๋Š” ๋ณต์‚ฌํ•œ ๊ณต๊ฐœ ํ‚ค๋ฅผ ๋ถ™์—ฌ๋„ฃ์Šต๋‹ˆ๋‹ค.
    • Add SSH key ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ ๋“ฑ๋ก์„ ์™„๋ฃŒํ•ฉ๋‹ˆ๋‹ค.
    • How to chek SSH key: SSH Key ํ™•์ธํ•˜๋Š” ๋ฒ•
        # Ubuntu ๋˜๋Š” Windows์—์„œ ์‹คํ–‰
        cat ~/.ssh/id_rsa_github.pub


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

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

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

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

4. (์ถ”๊ฐ€) Tips! id_rsa๋ง๊ณ  ๋‹ค๋ฅธ ์ด๋ฆ„์œผ๋กœ ์„ค์ •ํ•˜๊ธฐ

๐Ÿคฆโ€โ™‚๏ธ ๊ฐ€๋” ์‚ฌ์šฉํ•˜๋‹ค ๋ณด๋ฉด, ๊ฐœ์ธ ํ‚ค์™€ ๊ณต๊ฐœ ํ‚ค๊ฐ€ ์„œ๋กœ ๋‹ค๋ฅด๋‹ค๋Š” ์—๋Ÿฌ์™€ ๋งˆ์ฃผ์น˜๊ฒŒ ๋ ๋•Œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋Ÿด๋•Œ๋Š” ๊ฐœ์ธ ํ‚ค์™€ ๊ณต๊ฐœ ํ‚ค๊ฐ€ ์„œ๋กœ ๋‹ค๋ฅด๋‹ค๋ฉด, ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์ƒˆ๋กœ์šด ํ‚ค ์Œ์„ ์ƒ์„ฑํ•˜๊ณ , ๊ณต๊ฐœ ํ‚ค๋ฅผ ๋‹ค์‹œ ๋“ฑ๋กํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ๋‹จ๊ณ„๋ฅผ ๋”ฐ๋ฅด์„ธ์š”:

  1. ์ƒˆ SSH ํ‚ค ์Œ ์ƒ์„ฑ

    • ์ƒˆ๋กœ์šด SSH ํ‚ค ์Œ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ์กด ํ‚ค ํŒŒ์ผ์ด ์ด๋ฏธ ์กด์žฌํ•œ๋‹ค๋ฉด ์ด๋ฆ„์„ ๋‹ค๋ฅด๊ฒŒ ์„ค์ •ํ•˜์„ธ์š”.

      ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    • ์ด๋ฉ”์ผ์€ GitHub ๊ณ„์ •์— ์—ฐ๊ฒฐ๋œ ์ด๋ฉ”์ผ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

    • ๊ธฐ๋ณธ ์ €์žฅ ๊ฒฝ๋กœ(~/.ssh/id_rsa)๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ๊ธฐ์กด ํŒŒ์ผ์ด ๋ฎ์–ด์“ฐ์—ฌ์งˆ ์ˆ˜ ์žˆ์œผ๋‹ˆ, ์ƒˆ๋กœ์šด ์ด๋ฆ„์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค(e.g., ~/.ssh/id_rsa_new).

    • ์˜ˆ:

      Enter file in which to save the key (/home/user/.ssh/id_rsa): /home/user/.ssh/id_rsa_new
  1. ์ƒˆ๋กœ ์ƒ์„ฑ๋œ ๊ณต๊ฐœ ํ‚ค ํ™•์ธ

    • ์ƒ์„ฑ๋œ ๊ณต๊ฐœ ํ‚ค๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค:

      cat ~/.ssh/id_rsa_new.pub
    • ์ถœ๋ ฅ๋œ ํ‚ค๋ฅผ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.

  1. GitHub์— ์ƒˆ ๊ณต๊ฐœ ํ‚ค ๋“ฑ๋ก

    • GitHub ์›น์‚ฌ์ดํŠธ์—์„œ ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค:

      1. Settings > SSH and GPG keys๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.
      2. New SSH key ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
      3. Title์— ํ‚ค์˜ ์ด๋ฆ„(์˜ˆ: "New Key")์„ ์ž…๋ ฅํ•˜๊ณ , Key ์ž…๋ ฅ๋ž€์— ๋ณต์‚ฌํ•œ ๊ณต๊ฐœ ํ‚ค๋ฅผ ๋ถ™์—ฌ๋„ฃ์Šต๋‹ˆ๋‹ค.
      4. Add SSH key๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
  1. ์ƒˆ ํ‚ค๋ฅผ SSH ์—์ด์ „ํŠธ์— ์ถ”๊ฐ€

    • ์ƒˆ๋กœ ์ƒ์„ฑ๋œ ๊ฐœ์ธ ํ‚ค๋ฅผ SSH ์—์ด์ „ํŠธ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค:
      ssh-add ~/.ssh/id_rsa_new
      • ํ˜„์žฌ ๋กœ๋“œ๋œ ํ‚ค๋ฅผ ํ™•์ธํ•˜์—ฌ ์ถ”๊ฐ€๋œ ํ‚ค๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋“ฑ๋ก๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค:
       ssh-add -l

๐Ÿ’ป SSH ์—์ด์ „ํŠธ(Agent) ์‚ฌ์šฉํ•˜๊ธฐ
SSH ์—์ด์ „ํŠธ๋Š” SSH ํ‚ค๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅํ•˜์—ฌ ์ธ์ฆ ๊ณผ์ •์„ ๊ฐ„์†Œํ™”ํ•ฉ๋‹ˆ๋‹ค.
GitHub์™€์˜ ์—ฐ๊ฒฐ์„ ์œ„ํ•ด ์—์ด์ „ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

  • SSH ์—์ด์ „ํŠธ ์‹œ์ž‘:
    eval "$(ssh-agent -s)"
  • ํ‚ค ์ถ”๊ฐ€: ์ƒ์„ฑํ•œ ํ‚ค๋ฅผ SSH ์—์ด์ „ํŠธ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค:
    ssh-add ~/.ssh/id_rsa_github
  • ์ €์žฅ๋œ ํ‚ค ํ™•์ธ: ์ €์žฅ๋œ ํ‚ค ๋ชฉ๋ก์ด ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.
    ssh-add -l
  • ์—์ด์ „ํŠธ ์ข…๋ฃŒ: ์ž‘์—…์„ ์ข…๋ฃŒํ•˜๊ณ  ์‹ถ์œผ๋ฉด SSH ์—์ด์ „ํŠธ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค:
    ssh-agent -k
  1. ์ƒˆ ํ‚ค๋กœ ์ธ์ฆ ํ…Œ์ŠคํŠธ
  • SSH ํ‚ค๊ฐ€ ์ œ๋Œ€๋กœ ์„ค์ •๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋ฉด ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:

    ssh -T git@github.com
  • ์„ฑ๊ณต ๋ฉ”์‹œ์ง€:

    Hi username! You've successfully authenticated, but GitHub does not provide shell access.

(์ฐธ๊ณ ) SSH ์—์ด์ „ํŠธ์™€ Config ํŒŒ์ผ์˜ ์ฐจ์ด

  • SSH ์—์ด์ „ํŠธ:
    • ์ƒ์„ฑ๋œ SSH ํ‚ค๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅํ•˜์—ฌ ์ธ์ฆ์„ ๊ฐ„์†Œํ™”ํ•ฉ๋‹ˆ๋‹ค.
    • ssh-add ๋ช…๋ น์–ด๋กœ ํ‚ค๋ฅผ ๋“ฑ๋กํ•˜๋ฉด ์—ฐ๊ฒฐ ์‹œ ์ž๋™์œผ๋กœ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • Config ํŒŒ์ผ ์„ค์ •:
    • SSH ์—ฐ๊ฒฐ ์‹œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ํ‚ค๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
    • ํŠน์ • ํ˜ธ์ŠคํŠธ(Host github.com)์— ๋Œ€ํ•ด ์–ด๋–ค ํ‚ค ํŒŒ์ผ์„ ์‚ฌ์šฉํ• ์ง€ ์„ค์ •ํ•˜๋Š” ๋ฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
    • SSH ์—์ด์ „ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.

(์ฐธ๊ณ ) Config ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ 

  • ์—ฌ๋Ÿฌ SSH ํ‚ค ๊ด€๋ฆฌ:
    • GitHub, GitLab ๋“ฑ ์—ฌ๋Ÿฌ ํ”Œ๋žซํผ์—์„œ ์„œ๋กœ ๋‹ค๋ฅธ SSH ํ‚ค๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ~/.ssh/config ํŒŒ์ผ์„ ์„ค์ •ํ•˜์—ฌ ๊ฐ ํ˜ธ์ŠคํŠธ์— ์ ํ•ฉํ•œ ํ‚ค๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ์˜ˆ:
      Host github.com
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_rsa_github
      Host gitlab.com
        HostName gitlab.com
        User git
        IdentityFile ~/.ssh/id_rsa_gitlab
  • ๊ธฐ๋ณธ ํ‚ค ์ง€์ •:
    • ํŠน์ • ํ”„๋กœ์ ํŠธ์—์„œ ๋ณ„๋„๋กœ ์ƒ์„ฑํ•œ ํ‚ค๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

(์ฐธ๊ณ ) ์—์ด์ „ํŠธ์™€ Config๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ

  • ๋ถ€์ œ ์–ด๋–ค๊ฒŒ ์šฐ์„ ์‹œ ๋˜๋Š”๊ฐ€?
  • Config ํŒŒ์ผ์—์„œ ๋ช…์‹œ๋œ IdentityFile ์„ค์ •์€ SSH ์—์ด์ „ํŠธ์—์„œ ๊ด€๋ฆฌ๋˜๋Š” ํ‚ค๋ณด๋‹ค ์šฐ์„ ํ•ฉ๋‹ˆ๋‹ค.
  • ์ฆ‰, Config ํŒŒ์ผ์— ์ง€์ •๋œ ํ‚ค๊ฐ€ ์žˆ๋‹ค๋ฉด SSH ์—์ด์ „ํŠธ์— ๋“ฑ๋ก๋˜์ง€ ์•Š์•„๋„ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

์ •๋ฆฌ

  • ์—์ด์ „ํŠธ๋Š” ์ธ์ฆ ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ฐ„์†Œํ™”ํ•˜๊ณ ,
  • Config ํŒŒ์ผ์€ ํ‚ค ์‚ฌ์šฉ ๊ทœ์น™์„ ๋ช…์‹œ์ ์œผ๋กœ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

๋‘ ๊ฐ€์ง€๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์ˆ˜์˜ ํ‚ค๋ฅผ ๊ด€๋ฆฌํ•˜๊ฑฐ๋‚˜ ์ธ์ฆ์„ ํŽธ๋ฆฌํ•˜๊ฒŒ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๊ณผ์ •์„ ๋”ฐ๋ผ ์ƒˆ๋กœ์šด SSH ํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ๊ณต๊ฐœ ํ‚ค๋ฅผ ๋“ฑ๋กํ•˜๋ฉฐ, ์ธ์ฆ์„ ์žฌ์„ค์ •ํ•˜๋ฉด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋ฉ๋‹ˆ๋‹ค! ๐Ÿ˜Š

๊ฒฐ๋ก 

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

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

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

profile
Always be passionate โœจ

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