root@ubuntu:~# sudo adduser git 'git' 사용자를 추가 중... 새 그룹 'git' (1003) 추가 ... 새 사용자 'git' (1001) 을(를) 그룹 'git' (으)로 추가 ... '/home/git' 홈 디렉터리를 생성하는 중... '/etc/skel'에서 파일들을 복사하는 중... 새 UNIX 암호 입력: 새 UNIX 암호 재입력: passwd: password updated successfully Changing the user information for git Enter the new value, or press ENTER for the default Full Name []: durumul Room Number []: Work Phone []: Home Phone []: Other []: 정보가 올바릅니까? [Y/n] y root@ubuntu:~# sudo su git git@ubuntu:/root$ mkdir ~/.ssh git@ubuntu:/root$ chmod 700 ~/.ssh git@ubuntu:/root$ ll ls: '.' 디렉터리를 열 수 없음: 허가 거부 git@ubuntu:/root$ ll ls: '.' 디렉터리를 열 수 없음: 허가 거부 git@ubuntu:/root$ whoami git git@ubuntu:/root$ cd git@ubuntu:~$ ll 합계 24 drwxr-xr-x 3 git git 4096 7월 3 00:24 ./ drwxr-xr-x 5 root root 4096 7월 3 00:23 ../ -rw-r--r-- 1 git git 220 7월 3 00:23 .bash_logout -rw-r--r-- 1 git git 3771 7월 3 00:23 .bashrc -rw-r--r-- 1 git git 807 7월 3 00:23 .profile drwx------ 2 git git 4096 7월 3 00:24 .ssh/ git@ubuntu:~$ touch ~/.ssh/authorized_keys git@ubuntu:~$ chmod 600 ~/.ssh/authorized_keys git@ubuntu:~$ mkdir /home/git/homi-repo.git git@ubuntu:~$ ll 합계 28 drwxr-xr-x 4 git git 4096 7월 3 00:25 ./ drwxr-xr-x 5 root root 4096 7월 3 00:23 ../ -rw-r--r-- 1 git git 220 7월 3 00:23 .bash_logout -rw-r--r-- 1 git git 3771 7월 3 00:23 .bashrc -rw-r--r-- 1 git git 807 7월 3 00:23 .profile drwx------ 2 git git 4096 7월 3 00:24 .ssh/ drwxrwxr-x 2 git git 4096 7월 3 00:25 homi-repo.git/ git@ubuntu:~$ cd homi-repo.git/ git@ubuntu:~/homi-repo.git$ git init --bare /home/git/homi-repo.git/ 안의 빈 깃 저장소를 다시 초기화했습니다 git@ubuntu:~/homi-repo.git$ ll 합계 40 drwxrwxr-x 7 git git 4096 7월 3 00:25 ./ drwxr-xr-x 4 git git 4096 7월 3 00:25 ../ -rw-rw-r-- 1 git git 23 7월 3 00:25 HEAD drwxrwxr-x 2 git git 4096 7월 3 00:25 branches/ -rw-rw-r-- 1 git git 66 7월 3 00:25 config -rw-rw-r-- 1 git git 73 7월 3 00:25 description drwxrwxr-x 2 git git 4096 7월 3 00:25 hooks/ drwxrwxr-x 2 git git 4096 7월 3 00:25 info/ drwxrwxr-x 4 git git 4096 7월 3 00:25 objects/ drwxrwxr-x 4 git git 4096 7월 3 00:25 refs/ git@ubuntu:~/homi-repo.git$ pwd /home/git/homi-repo.git git@ubuntu:~/homi-repo.git$ cd /home/git git@ubuntu:~$ ll 합계 28 drwxr-xr-x 4 git git 4096 7월 3 00:25 ./ drwxr-xr-x 5 root root 4096 7월 3 00:23 ../ -rw-r--r-- 1 git git 220 7월 3 00:23 .bash_logout -rw-r--r-- 1 git git 3771 7월 3 00:23 .bashrc -rw-r--r-- 1 git git 807 7월 3 00:23 .profile drwx------ 2 git git 4096 7월 3 00:24 .ssh/ drwxrwxr-x 7 git git 4096 7월 3 00:25 homi-repo.git/ git@ubuntu:~$ chown -R git:git test-repo.git chown: 'test-repo.git'에 접근할 수 없습니다: 그런 파일이나 디렉터리가 없습니다 git@ubuntu:~$ ll 합계 28 drwxr-xr-x 4 git git 4096 7월 3 00:25 ./ drwxr-xr-x 5 root root 4096 7월 3 00:23 ../ -rw-r--r-- 1 git git 220 7월 3 00:23 .bash_logout -rw-r--r-- 1 git git 3771 7월 3 00:23 .bashrc -rw-r--r-- 1 git git 807 7월 3 00:23 .profile drwx------ 2 git git 4096 7월 3 00:24 .ssh/ drwxrwxr-x 7 git git 4096 7월 3 00:25 homi-repo.git/ git@ubuntu:~$ chown -R git:git homi-repo.git git@ubuntu:~$ ll 합계 28 drwxr-xr-x 4 git git 4096 7월 3 00:25 ./ drwxr-xr-x 5 root root 4096 7월 3 00:23 ../ -rw-r--r-- 1 git git 220 7월 3 00:23 .bash_logout -rw-r--r-- 1 git git 3771 7월 3 00:23 .bashrc -rw-r--r-- 1 git git 807 7월 3 00:23 .profile drwx------ 2 git git 4096 7월 3 00:24 .ssh/ drwxrwxr-x 7 git git 4096 7월 3 00:25 homi-repo.git/ git@ubuntu:~$ 'git' 사용자를 추가 중... 새 그룹 'git' (1003) 추가 ... 새 사용자 'git' (1001) 을(를) 그룹 'git' (으)로 추가 ... '/home/git' 홈 디렉터리를 생성하는 중... |
|
ssh-keygen -t rsa git@ubuntu:~$ Other []: Other: 명령을 찾을 수 없습니다 git@ubuntu:~$ 정보가 올바릅니까? [Y/n] y 정보가: 명령을 찾을 수 없습니다 git@ubuntu:~$ root@ubuntu:~# sudo su git root@ubuntu:~#: 명령을 찾을 수 없습니다 git@ubuntu:~$ git@ubuntu:/root$ mkdir ~/.ssh bash: git@ubuntu:/root$: 그런 파일이나 디렉터리가 없습니다 git@ubuntu:~$ git@ubuntu:/root$ chmod 700 ~/.ssh bash: git@ubuntu:/root$: 그런 파일이나 디렉터리가 없습니다 git@ubuntu:~$ git@ubuntu:/root$ ll bash: git@ubuntu:/root$: 그런 파일이나 디렉터리가 없습니다 git@ubuntu:~$ ls: '.' 디렉터리를 열 수 없음: 허가 거부 ^Z [1]+ 정지됨 ls: '.' 디렉터리를 열 수 없음: 허가 거부 git@ubuntu:~$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/git/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/git/.ssh/id_rsa. Your public key has been saved in /home/git/.ssh/id_rsa.pub. The key fingerprint is: SHA256:z7uLorZiwwMLItKG60/FEBl9Mh2YcZ74EfCwiWJ43Fc git@ubuntu The key's randomart image is: +---[RSA 2048]----+ | o++*+E | |.. oo*O+o | |.ooo.+== | |... o.. . | | o o .S | |B o . o | |=* . o | |o B . . . . | |.o.*oo .. +o | +----[SHA256]-----+ git@ubuntu:~$ ^C git@ubuntu:~$ |
|
공개키 Ununtu의 git 사용자 ~/.ssh 디렉토리에 복사
# ssh-copy-id -i [공개키 위치] git@[ip-address]
ssh-copy-id -i ~/.ssh/id_rsa.pub git@192.168.111.100
# 오류발생 시 키스캔
ssh-keyscan -p 22 192.168.111.100 >> ~/.ssh/known_hosts
git@[host] 에서 host에 대한 인증 필요
host ssh keyscan
host 의 git 계정 비밀번호 입력하면 완료
/home/git/.ssh/authorized_keys 에 복사 확인
프로젝트 디렉터리를 만들고 깃 저장소 초기화를 진행합니다.
mkdir GitProject
cd GitProject
git init
git 원격 저장소에 현재 디렉토리 추가하기
git remote add origin git@192.168.111.100:/home/git/test-repo.git
테스트용 파일을 생성하고 git 명령어를 수행해 봅니다.
touch index.html # 파일생성
git add * # 모든파일 추가
git config user.email "ubuntu@test.com" # 사용자 이메일 설정
git config user.name "ubuntu" # 사용자 이름 설정
git commit -m "커밋테스트" # 커밋
git 원격 저장소로 PUSH 하기
git push --set-upstream origin master
# git 기본 명령어
git status # 현재 상태 확인
변경사항 있는경우
git push 후 상
git log # 전체 로그 확인
git init # git 저장소 생성하기
git clonw https:~~~ # 저장소 복제 및 다운로드
#저장소에 코드 추가
git add
git add *
git add -A # 커밋에 파일 변경 사항 모두 포함
git commit -m "commit messge 작성" # 커밋 생성
git push origin master # 변경 사항 원격 서버 업로드 (push)
git pull # 원격 저장소변경 내용 현재 디렉토리로 가져오기 (pull)
git diff [branch name] [another branch name] # merge 전에 바뀐 내용 비교
# 다른 컴퓨터에서 Visual Studio Code 에 git-server repository 연동하기
테스트 프로젝트 생성
SOURCE CONTROL 메뉴 - Initialize Repository - Manage Unsafe Repositories - 해당폴더 클릭
.
프로젝트 폴더 확인하면 .git / . gitignore 생성 확인
git 설치 후 name / email 설정하지 않고 Commit 하면 경고창이 뜬다
# 터미널에서 Git Bash 선택하고 아래 명령어로 name, email 설정
git config --global user.email "email@email.com"
git config --global user.name "name"
SSH 키를 생성하고 git server 에 등록
ssh-keygen -t rsa
생성된 키 위치 확인
# 호스트 키스캔
ssh-keyscan -p 22 [host-ip-address] >> ~/.ssh/known_hosts
# ssh-copy-id -i [공개키 위치] git@[ip-address] 공개키 전송
ssh-copy-id -i /c/Users/[user-name]/.ssh/id_rsa.pub git@[host-ip-address]
git server 에서 키입력 확인
git server 에서 연동할 폴더 생성
# 폴더생성 test-repo.git
mkdir /home/git/git-repository/testgit.git
# 폴더로 이동
cd /home/git/git-repository/testgit.git
# git repo 초기화
git init --bare
# 재귀적으로 디렉토리 및 파일 권한 변경
chown -R git:git /home/git/git-repository/testgit.git
또는 Client Git Bash 에서 SSH 접속하여 작업 진행
ssh git@[ip-address]
준비된 git server 폴더에 연동하기
git remote add origin git@[ip address]:/[경로]
git remote -v #원격지 설정 확인
git push --set-upstream origin main # 원격지 브렌치 연동
# 로컬 저장소에 브렌치와 원격지에 추가하려는 브렌치명 일치시켜야함 ex) master -> origin master
# 현재 브렌치 확인
git branch
# 필요시 브렌치 생성
git checkout -b [branch-name]
이제 VS Code UI 나 확장도구도 연동되어 편하게 사용 가능
추가보안설정! 여러 사용자들이 ssh 를 통해 접속하기 때문에 서버에서 git 계정의 bash 사용 권한을 제한해야 합니다!
# 설정파일 열기
sudo vi /etc/passwd
# git 계정의 설정을 변경합니다. 맨 뒷 부분만 바꿔주면 됩니다.
# 변경 전 >> 후
git ~~~~~~~ /bin/bash >> git ~~~~~~~ /bin/git-shell
이후 저장소 추가시 root 권한으로 폴더를 만들고 폴더소유권한을 git 으로 설정해 주면 됩니다.
더 자사한것은 Git 서버 만들기 Ubuntu 22.04 (https://it-racoon.tistory.com/14)
Git 서버 만들기 Ubuntu 22.04
Ubuntu 22.04 에서 git server를 만들어 보겠습니다. # Ubuntu 서버에 git 설치하기 # apt 업데이트 sudo apt-get update # git 설치 sudo apt-get install -y git # 설치확인 git --version # git-shell 경로 확인 which git-shell # 결과
it-racoon.tistory.com
구글신께 기도해라!
'Server | Network' 카테고리의 다른 글
동시접속 C10K SOCKET (3) | 2024.04.08 |
---|---|
메세지 브로커(MQ) (0) | 2024.04.08 |
Slowly RabbitMQ shutdown 이 너무 느릴때 해결방법 (0) | 2020.02.26 |
네트워크 모니터링 (snmp,syslog,usercmd logging and watch) (0) | 2015.01.08 |
서버 명령어 모니터링 (0) | 2014.11.09 |