관리 메뉴

bright jazz music

blog14 : Github SSH 설정, 프로젝트 올리기 본문

Projects/blog

blog14 : Github SSH 설정, 프로젝트 올리기

bright jazz music 2023. 1. 29. 18:33

1. SSH를 사용한 통신 환경 설정

1-1 github 로그인

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/about-ssh

 

About SSH - GitHub Docs

You can access and write data in repositories on GitHub.com using SSH (Secure Shell Protocol). When you connect via SSH, you authenticate using a private key file on your local machine. For more information about SSH, see Secure Shell on Wikipedia. When yo

docs.github.com

참고해서

 

setting에 추가한다.

 

 

1-2 ssh-key 생성

Enter passphrase가 비밀번호 입력인데 입력 안 했음.

 

c/Users/user/.ssh/id_rsa 밑에 파일 생성됨.

id_rsa : 개인키 파일
id_rsa.pub : 공개키 파일

 

개인키 파일은 외부에 절대 공개해서는 안 된다.

개인키 파일의 내부는 아래와 같이 되어 있다. ***로 내용을 바꾸었다.

 

-----BEGIN OPENSSH PRIVATE KEY-----
b3B*****************************************************
b3B*****************************************************
b3B*****************************************************
b3B*****************************************************
b3B*****************************************************

...

b3B*****************************************************
6qaEHhUSTlUkBXMUWcA/VxF+veLvd3lngbwJtsWjbRc4BHFluRRNBW1n
mTTQxAQIDBAUGb3B**************************
-----END OPENSSH PRIVATE KEY-----

 

공개키 파일은 아래와 같이 되어 있다.

ssh-rsa AAAAB3NzaC1yc2 ... qLLVm0KtI4DHFad9Tsqcuq3jU= user@DESKTOP-Q7HBM41

 

id_rsa로 시작하는 파일들의 권한을 수정해준다.

 

1-3 깃허브 세팅에서 SSH Key 추가

 

공캐키의 값을 클립보드(메모리)에 복사해 준다.


| pbcopy 사용

 

cat ./id_rsa.pub | pbcopy

 

윈도우 환경에서는

| clip 명령어를 사용한다.

cat ./id_rsa.pub | clip

 

붙여 넣는다. shift + insert 키 사용. 타이틀은 비워도 된다. 완료했으면 Add SSH key를 누른다.

 

추가 되었다.

 

이렇게 되면, 이 컴퓨터가 개인키(여기서는 c:user/user/.ssh/에 존재하는 id_rsa)를 이용해서 해당 계정의 Repository에 접근할 수 있게 된다. 통신할 준비가 된 것이다.

 

 

2. Repository 만들기

 

readme 파일과 깃 이그노어를 만들면 그 자체로 커밋이 된다. 그런데 이 경우 기존의 프로젝트와 싱크가 맞지 않기 때문에 먼저 pull을 한 뒤에 다시 커밋을 해야한다. 이것이 번거롭기 때문에 이번에는 리드미 파일과 깃 이그노어를 만들지 않고 진행한다.

 

 

3. README.md 푸시하기

echo "# blog" >> README.md	//해당 디렉토리에 README.md 파일 생성
git init	//해당 디렉토리에 .git 디렉토리 생성
git add README.md //스테이지에 올리기
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/h~~~~~7/blog.git
git push -u origin main

- 처음 README.md 의 내용은 #blog 뿐이다.

- .git 디렉토리의 config파일에는 설정한 리모트 레포지토리 경로가 나와있다. 설정에 문제가 있을 경우 참고해 볼 수 있다.

 

 

커밋하고, 커밋 시의 이름, 이메일 수정(local:여기서만)

 

그래도 git log를 쳐보면 바뀌지 않는다. 그 다음 커밋부터 바뀌기 때문이다.

첫 번째 커밋을 되돌리면 된다. 어떻게 해야할까?

 

$ git update-ref -d HEAD

README.md는 스테이지에 올라가 있는 상태이다.

 

재 커밋. 참고로 ctrl + r을 눌러서 이전에 썼던 명령어의 일부를 검색하면 검색어가 나온다.
log만 쳤는데 git log가 나온다. 이 상태에서 엔터 누르면 git log으로 입력된다.
현재 생성된 repository를 origin으로 remote로 등록한다.
main브랜치에 push
푸쉬 되었다.

4. .gitignore  설정하고 푸시하기

https://github.com/spring-projects/spring-boot/blob/main/.gitignore#L4

 

이와 같은 프로젝트의 루트 디렉토리에 .gitignore파일을 만들고 아래의 내용을 붙여 넣어준다.

 

*#
*.iml
*.ipr
*.iws
*.jar
*.sw?
*~
.#*
.*.md.html
.DS_Store
.attach_pid*
.classpath
.factorypath
.gradle
.idea
.metadata
.project
.recommenders
.settings
.springBeans
.vscode
/code
MANIFEST.MF
_site/
activemq-data
bin
build
!/**/src/**/bin
!/**/src/**/build
build.log
dependency-reduced-pom.xml
dump.rdb
interpolated*.xml
lib/
manifest.yml
out
overridedb.*
target
.flattened-pom.xml
secrets.yml
.gradletasknamecache
.sts4-cache

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn.  Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

 

 

그러면 해당 디렉토리에서 .gitignore의 내용에 저촉되는 것들은 전부 commit 가능 파일에서 제외된다.

 

이제 코드를 올린다.

리포지토리에 푸시 되었다.

 

 

5. 만약 다른 pc에서 클론하려는 경우

ssh로 키를 만들고, 공개키를 깃허브 세팅에 넣어준다.

그리고 

 

$ git clone git@github.com:h~~7/blog.git

 

해주면 된다.

Comments