๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
IT-Engineering

git push์‹œ ์ž๋™ ๋กœ๊ทธ์ธ ์„ค์ • - SSH ์„ค์ •์œผ๋กœ username, password ๊ทธ๋งŒ ์ž…๋ ฅํ•˜์ž

by ๐Ÿงž‍โ™‚๏ธ 2020. 6. 8.
๋ฐ˜์‘ํ˜•

github respository์— git push -u origin master๋ฅผ ํ–ˆ์„ ๋•Œ ์•„๋ž˜์™€ ๊ฐ™์ด ์ž๊พธ ๋กœ๊ทธ์ธ์„ ์š”์ฒญํ•˜๋Š” ๊ฒฝ์šฐ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ์ •๋ฆฌ.
repository์ฃผ์†Œ๋ฅผ https๋กœ ๋ฐ›์•„์„œ ์ฒ˜๋ฆฌํ•˜๋˜ ๊ฒฝ์šฐ์— ํ”„๋กœํ† ์ฝœ์„ ssh๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

์ด ํฌ์ŠคํŒ…์€ ๋ฆฌ๋ˆ…์Šค ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•ด ์ž‘์„ฑ๋˜์—ˆ๋‹ค.

(master)$ git push -u origin master  
Username for 'https://github.com': username  
Password for 'https://username@github.com': *******

๋ฐฉ๋ฒ•์€ ๋‘ ๊ฐ€์ง€ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.

  1. sshํ‚ค๋ฅผ ์ด๋ฏธ ์•Œ๊ณ  ์žˆ๊ฑฐ๋‚˜ ์žˆ๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์œผ๋‹ˆ ํ™•์ธํ•ด๋ด์•ผ๊ฒ ์Œ.
  2. sshํ‚ค๊ฐ€ ํ™•์‹คํžˆ ์—†์Œ. ์ƒˆ๋กœ ๋งŒ๋“ค์–ด์•ผ๊ฒ ์Œ.

1๋ฒˆ๋ถ€ํ„ฐ ์„ค๋ช…ํ•˜๊ฒ ๋‹ค.

1๋ฒˆ. SSHํ‚ค ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ

  1. ํ„ฐ๋ฏธ๋„์„ ์—ฐ๋‹ค.
  2. ls -al ~/.ssh ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ SSHํ‚ค๊ฐ€ ์ด๋ฏธ ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.
    $ ls -al ~/.ssh
    # Lists the files in your .ssh directory, if they exist
  3. ์ด๋ฏธ ๊ณต๊ฐœ SSHํ‚ค๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋œฐ ๊ฒƒ์ด๋‹ค. ๋””ํดํŠธ๋กœ ์„ค์ •๋œ ํŒŒ์ผ๋ช…์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
  • id_rsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub

๋งŒ์•ฝ์— ์—†๋‹ค๋ฉด 2๋ฒˆ์œผ๋กœ ๋„˜์–ด๊ฐ€์ž.

2๋ฒˆ. ์ƒˆ๋กœ์šด SSHํ‚ค ๋งŒ๋“ค๊ธฐ

  1. ํ„ฐ๋ฏธ๋„์„ ์—ฐ๋‹ค.
  2. ์•„๋ž˜ ํ…์ŠคํŠธ๋ฅผ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•œ๋‹ค. Email์ฃผ์†Œ๋Š” ๋ณ€๊ฒฝํ•˜๊ธธ ๋ฐ”๋ž€๋‹ค.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

์•„๋ž˜์™€ ๊ฐ™์€ ๋ฉ”์‹œ์ง€๊ฐ€ ๋œฐ ๊ฒƒ์ด๋‹ค.

> Generating public/private rsa key pair.

"Enter a file in which to save the key,"๋ผ๋Š” ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜์˜ค๋ฉด ์—”ํ„ฐํ‚ค๋ฅผ ๋ˆ„๋ฅด๋ฉด ๋œ๋‹ค.

๊ทธ๋Ÿฌ๋ฉด ๋””ํดํŠธ ๊ฒฝ๋กœ๋กœ ์„ค์ •์ด ๋œ๋‹ค.

> Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]

๋‹ค์Œ์œผ๋กœ๋Š” ์•”ํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ผ๊ณ  ๋œจ๋Š”๋ฐ, ์•”ํ˜ธ๋ฅผ ํ™•์ธ๊นŒ์ง€ ๋‘๋ฒˆ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

3๋ฒˆ. SSHํ‚ค ๋ณต์‚ฌํ•˜๊ธฐ

๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด SSHํ‚ค๋ฅผ ๋ณต์‚ฌํ•œ๋‹ค. ๊ฒฝ๋กœ๋ฅผ ๋ณ€๊ฒฝํ•ด์ฃผ์—ˆ์„ ๊ฒฝ์šฐ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋„ ๊ทธ์— ๋งž๊ฒŒ ๋ณ€๊ฒฝํ•ด์•ผ ํ•œ๋‹ค.

$ sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)
$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

4๋ฒˆ. Github์ €์žฅ์†Œ์— SSHํ‚ค ์„ค์ •ํ•˜๊ธฐ

  1. ์•„๋ž˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์€ ๋ฉ”๋‰ด์—์„œ Settings ํด๋ฆญ

  1. ์•„๋ž˜์˜ ๊ทธ๋ฆผ์„ ์ฐพ์•„์„œ SSH and GPG keys ํด๋ฆญ

  1. New SSH Key ํด๋ฆญ

  1. ์•„๋ž˜์˜ Key๊ฐ’์— ๋ณต์‚ฌ๋œ SSHํ‚ค ๋ถ™์—ฌ๋„ฃ๊ธฐ

  1. Add SSH Key ์ž…๋ ฅ

  1. ์•”ํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์ตœ์ข… ํ™•์ธ

5๋ฒˆ. GitHub Repository๋ฅผ HTTPS์—์„œ SSH๋กœ ์ „ํ™˜

  1. ๋ณธ์ธ์˜ Repository์—์„œ Clone or Download ๋ฒ„ํŠผ ํด๋ฆญ

  1. SSH ์ฃผ์†Œ๋กœ ์ „ํ™˜

  1. ํ•ด๋‹น SSH ์ฃผ์†Œ ๋ณต์‚ฌ (์œ„์˜ ํด๋ฆฝ๋ณด๋“œ ๋ฒ„ํŠผ ํด๋ฆญ ํ˜น์€ ์ฃผ์†Œ ๋“œ๋ž˜๊ทธํ•ด์„œ ๋ณต์‚ฌ)

  2. ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ํ„ฐ๋ฏธ๋„์—์„œ ์ž…๋ ฅ(์‚ฌ์šฉ์ž ์ด๋ฆ„๊ณผ ์ €์žฅ์†Œ์ž…๋ ฅ ๋ณธ์ธ์— ๋งž๊ฒŒ ์ž…๋ ฅ)

(master)$ git config remote.origin.url git@github.com:username/repository.git
The authenticity of host 'github.com (52.78.231.108)' can't be established.
RSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? [Enter 'yes']
Warning: Permanently added 'github.com,52.78.231.108' (RSA) to the list of known hosts.
  1. ์•”ํ˜ธ ์ž…๋ ฅ์„ ์š”์ฒญํ•˜๋ฉด ์•ž์—์„œ ์„ค์ •ํ•œ ์•”ํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

์—ฌ๊ธฐ๊นŒ์ง€ ๋งˆ์ณค์œผ๋ฉด ์ด์ œ ๋‹ค์‹œ git push -u origin master๋ฅผ ์ˆ˜ํ–‰ํ•ด๋ณด์ž.
์•„๋งˆ๋„ ์ž˜ ๋  ๊ฒƒ์ด๋‹ค.

 

์ฐธ๊ณ :

GitHub๋งค๋‰ด์–ผ(https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account)

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€