소품집

[Git] Gitlab 프로젝트 생성과 ssh key 적용 본문

Github

[Git] Gitlab 프로젝트 생성과 ssh key 적용

sodayeong 2020. 3. 28. 20:23

 

리눅스 환경에서 작성한 파일 및 디렉토리등을 생성하고 Github에 파일을 연동하는 일이 많은데요.

그 환경을 구축하기 위해 '리눅스와 GitHub 연동하기' 를 해볼겁니다.


 

 

 

먼저, GitHub.com 에 접속한 후 파일이 담길 New project를 생성합니다.

 

 

u1015@workstation:~$ mkdir user_test

이제 리눅스로 가서 동일한 이름으로 파일을 생성해 줄건데요,
GitHub project 와 동일하게 디렉토리를 생성해줍니다.

저는 'user_test' 로 생성했습니다.

 

u1015@workstation:~$ cd .ssh
u1015@workstation:~/.ssh$ ls
id_ed2519.pub id_ed25519.pub known_hosts test

u1015@workstation:~$ ssh-keygen
Generating public/private rsa key pair

id_rsa.pub 파일이 없다면 ssh key가 있지 않은 겁니다. 

ssh-keygen 명령어로 key를 생성해줍니다.  

Enter file in which to save the key (/home/u1015/.ssh/id_rsa):
    /home/u1015/.ssh/id_rsa already exists.
    Overwrite (y/n)? y
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/u1015/.ssh/id_rsa.
    Your public key has been saved in /home/u1015/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:f5yrS37utjaGy5u4rCzHkAejwtyRa45Wm43yK+7ScOo u1015@workstation
    The key's randomart image is:
    +---[RSA 2048]----+
    | |
    | |
    | . |
    | oooooo|
    |o ..o+ S |
    |ooo=o . . . . |
    | *= =+ o.+ |
    |o=.=.oo. =.o*. |
    |*E+o.oo.+.O%=o |
    +----[SHA256]-----+

 

u1015@workstation:~$ cd .ssh
u1015@workstation:~/.ssh$ ls
id_ed2519.pub id_ed25519.pub id_rsa id_rsa.pub known_hosts test
u1015@workstation:~/.ssh$ cat id_rsa.pub

id_rsa 파일을 열고, ssh key를 복사해줍니다. 

 

 

 

ssh keys 를 획득하였다면,

gitlab에 로그인 > settings > SSH Keys 에 들어와, 획득한 key를 붙여 넣어준뒤 Add key를 클릭합니다.

 

 

다시 리눅스 창으로 돌아와, project overview Detail 창에 나와있는

Git global setup 과 clone을 입력해줍니다.

 

u1015@workstation:~/user_test$ git add README.md
u1015@workstation:~/user_test$ git commit -m "add read"
[master (최상위-커밋) e5ea21e] add read
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.md
u1015@workstation:~/user_test$ git push -u origin master
오브젝트 개수 세는 중: 3, 완료.
오브젝트 쓰는 중: 100% (3/3), 215 bytes | 0 bytes/s, 완료.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitlab.com:dayeong1021/user_test.git

[new branch] master -> master
master 브랜치가 리모트의 master 브랜치를 (origin에서) 따라가도록 설정되었습니다.
u1015@workstation:~/user_test$

 

 

commit 이 잘 된 것을 확인해보았습니다.

 

 

 

 

 

 

728x90
Comments