μžλ°”μŠ€ν¬λ¦½νŠΈλ₯Ό ν™œμ„±ν™” ν•΄μ£Όμ„Έμš”

d089 github deploy key둜 pullν•˜κΈ°

 ·  β˜• 2 min read

κ°œμš”

ν˜ΈμŠ€νŠΈμ—μ„œ git pull을 ν–ˆλŠ”λ°, λͺ»λ³΄λ˜ λ©”μ‹œμ§€κ°€ λ‚˜μ˜€λ©΄μ„œ pull이 λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.

8μ›” 13일 λΆ€ν„°, νŒ¨μŠ€μ›Œλ“œ 인증이 νμ§€λ˜μ—ˆλ‹€κ³  ν•©λ‹ˆλ‹€. λŒ€μ‹ μ— νΌμŠ€λ„ μ—‘μ„ΈμŠ€ 토큰을 μ‚¬μš©ν•˜λΌλŠ” λ©”μ‹œμ§€κ°€ λ‚˜μ™”μŠ΅λ‹ˆλ‹€.

[root@tkim.info tkim.info]# git pull
Username for 'https://github.com': crowdy@<mail address>
Password for 'https://crowdy<mail address>@github.com': 
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: unable to access 'https://github.com/crowdy/tkim.info/': The requested URL returned error: 403

λŒ€μ‘

μ„€λͺ…λœ λŒ€λ‘œ personal access token을 μ‚¬μš©ν• κΉŒ ν•˜λ‹€κ°€, ν˜ΈμŠ€νŠΈμ—μ„œλŠ” deploy key만 있으면 λ˜κ² λ‹€ μ‹Άμ–΄μ„œ deplot keyλ₯Ό μ„€μΉ˜ν–ˆμŠ΅λ‹ˆλ‹€. 방법은 λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

  1. ssh ν‚€ 생성

    ssh-keygen -trsa -b 4096 -C "{email}"
    

    을 μ‹€ν–‰ν•˜κ³  μ•”ν˜Έλ₯Ό λΉ„μ›Œ λ‘‘λ‹ˆλ‹€.

    생성 ν›„ .ssh ν΄λ”μ—μ„œ id_rsa 및 id_rsa.pub 파일이 μƒμ„±λœ 것을 λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€.

  2. repo의 “ν‚€ 배포” 섀정에 ssh ν‚€ μΆ”κ°€
    cat.ssh/id_cat.pub
    URL: https://github.com/ {user}/{repo}/keys/keys

  3. ν΄λΌμ΄μ–ΈνŠΈ μ‹œμŠ€ν…œμ— gitssh ν‚€ μ„€μ •
    GitλŠ” 일반적으둜 μ‚¬μš©μžμ˜ ν™ˆ 폴더 μ•„λž˜μ— μžˆλŠ” .ssh/id_rsa에 μžˆλŠ” ssh ν‚€λ₯Ό μ‚¬μš©ν•˜λ―€λ‘œ λ¨Όμ € μ‚¬μš©μžμ˜ ν™ˆ 디렉토리λ₯Ό μ°Ύμ•„μ•Ό ν•©λ‹ˆλ‹€.

    예λ₯Ό λ“€μ–΄ Ubuntu/Debianμ—μ„œ 기본적으둜 μ‚¬μš©μž www-data의 ν™ˆ λ””λ ‰ν† λ¦¬λŠ” /var/wwwwμ΄λ―€λ‘œ ssh ν‚€ νŒŒμΌμ€ /var/www/.ssh/id_rsa)μž…λ‹ˆλ‹€.

그런 λ‹€μŒ 1λ‹¨κ³„μ—μ„œ μƒμ„±ν•œ id_rsa νŒŒμΌμ„ ν•΄λ‹Ή λ””λ ‰ν† λ¦¬λ‘œ λ³΅μ‚¬ν•©λ‹ˆλ‹€.

λ‹€μŒμ„ 톡해 연결을 ν…ŒμŠ€νŠΈν•  수 μžˆμŠ΅λ‹ˆλ‹€.

sudo -u {user} ssh-T git@github.com

*Github의 ν‚€λ₯Ό μ•Œλ €μ§„ ν˜ΈμŠ€νŠΈμ— λΆ€μ—¬ν•΄μ•Ό ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

λͺ¨λ“  것이 잘 진행됐닀면, λ‹€μŒκ³Ό 같은 λ©”μ‹œμ§€λ₯Ό λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€.

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

그럼 μ€€λΉ„ μ™„λ£Œ!

주의: reporturl이 httpκ°€ μ•„λ‹Œ git ν”„λ‘œν† μ½œμ„ μ‚¬μš©ν•˜λŠ”μ§€ ν™•μΈν•˜μ‹­μ‹œμ˜€(μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.).

git@github.com:{user}/{repo}.git

이 μ•„λ‹ˆλΌ

https://github.com/{user}/{repo}.git

λ₯Ό μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.

λŒ€μ‘ 예

ν‚€ 생성

ν‚€λ₯Ό μƒμ„±ν•˜λŠ” λ™μž‘μ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

[root@tkim.info tkim.info]# ssh-keygen -t rsa -b 4096 -C "crowdy@<mail address>"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:brsxqDZ0N5pIXuOV+61xjtGkzZ0lMiRlz/nIJmsTODg crowdy@<mail address>
The key's randomart image is:
+---[RSA 4096]----+
|            o    |
|           o o . |
|          . . +  |
|         . + . o |
|        E.o * = o|
|    o +o=. B O + |
|   + =.*=o+ O o  |
|    =.+..+ O .   |
|   ...  oo+.o    |
+----[SHA256]-----+
[root@tkim.info tkim.info]# cat .ssh/id_rsa.pub
cat: .ssh/id_rsa.pub: No such file or directory
[root@tkim.info tkim.info]# cat $HOME/.ssh/id_rsa.pub
ssh-rsa <rsa string> crowdy@<mail address>

git pull ν…ŒμŠ€νŠΈ

[root@tkim.info tkim.info]# git remote -v
origin  https://github.com/crowdy/tkim.info (fetch)
origin  https://github.com/crowdy/tkim.info (push)
[root@tkim.info tkim.info]# git remote set-url origin git@github.com:crowdy/tkim.info.git
[root@tkim.info tkim.info]# git remote -v
origin  git@github.com:crowdy/tkim.info.git (fetch)
origin  git@github.com:crowdy/tkim.info.git (push)
[root@tkim.info tkim.info]# git pull
The authenticity of host 'github.com (52.69.186.44)' can't be established.
RSA key fingerprint is SHA256:<fingerprint string>.
RSA key fingerprint is MD5:<fingerprint bytes>.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.69.186.44' (RSA) to the list of known hosts.
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 18 (delta 13), reused 18 (delta 13), pack-reused 0
Unpacking objects: 100% (18/18), done.
From github.com:crowdy/tkim.info
   0762ff5..f68e68a  design     -> origin/design
Updating 0762ff5..f68e68a
Fast-forward
 docs/README_011_paypal.md                      |  12 ++++++++++
 1 files changed, 208 insertions(+), 14 deletions(-)
[root@tkim.info tkim.info]# 

github μ—μ„œ 확인

μ‚¬μš©μ΄ ν™•μΈλœ deploy keyλŠ” 이런 λͺ¨μŠ΅μ„ ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

d089_github_deploy_key.png

κ³΅μœ ν•˜κΈ°

tkim
글쓴이
tkim
Software Engineer