Thứ Ba, 20 tháng 5, 2014

// // 2 comments

CÀt đặt GIT Server

Trên Client tạo 1 cặp khóa SSH:
thehai@thehai-Vostro-3550:~$ ssh-keygen -C "thehai007@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/thehai/.ssh/id_rsa):
/home/thehai/.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/thehai/.ssh/id_rsa.
Your public key has been saved in /home/thehai/.ssh/id_rsa.pub.
The key fingerprint is:
01:92:be:32:1b:34:41:8d:26:a1:ba:66:9c:95:16:a8 thehai007@gmail.com
The key's randomart image is:
+--[ RSA 2048]----+
|.o.o...          |
|o = o. .         |
|.+ +    .        |
|o o +    .       |
|E. = .  S        |
|..B .            |
|.= =             |
|o .              |
|                 |
+-----------------+
Trên Server tạo 1 user git:
useradd git
passwd git
Sau đó tiến hành cài đặt git cho Server:
apt-get install git
Trên server, đăng nhập bằng tài khoản git
su -s /bin/bash - git
Ta sẽ chuyển file id_rsa.pub lên server
Trc tiên ta tạo thư mục .ssh và 1 file authorized_keys bên trong
git@serverwise:/$ mkdir ~/.ssh
git@serverwise:/$ touch ~/.ssh/authorized_keys
Sao chép nội dung trong file id_rsa.pub ở local vào file authorized_keys trên server:
thehai@thehai-Vostro-3550:~$ cat .ssh//id_rsa.pub | ssh root@192.168.1.14 "cat >> /home/git/.ssh/authorized_keys"
root@192.168.1.14's password:
Xem lại thử:
git@serverwise:/$ cat ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCZpwEhSawKfXnocmQn1h57YxVl9J1k9E8SrUfVZGHHyWmplgXCsSxeES6ff9+5ATEm0tJ/NXjHIfzdi4rAqLl0PQK0/57UmteJZVr2rTtLNpIllfeKPpTYQKcuMksoCM/fyWzps8ZonhBJnbUWuTgSAVbWhbHodt+Of06a3OUwiipZFNLav6ioPWQhsBrGEmlxmwfmvghLH0ezaHywsHB1lBGUo2w2KkEY4gbhQ2CekbB8sVVrf3DKZwLXoWTiOopfTQmeVzlztYUmT7/lYaPIeImoH703WV8LSHV1fkKpm0CW6Fjiva66Ir43DC4o4vh0iDwWnjuaYiCNdIP+dC1d thehai007@gmail.com
git@serverwise:/$

TRên server tạo folder git repo
git@serverwise:~$ mkdir my-project.git
git@serverwise:~$ cd my-project.git/
Tạo repo ban đầu
git@serverwise:~/my-project.git$ git --bare init
Initialized empty Git repository in /home/git/my-project.git/

Test từ  local:
Tạo 1 project bao gồm 1 số file sau đó đồng bộ lên local:
thehai@thehai-Vostro-3550:~$ mkdir my-project
thehai@thehai-Vostro-3550:~$ cd my-project/
thehai@thehai-Vostro-3550:~/my-project$ git init
Initialized empty Git repository in /home/thehai/my-project/.git/
thehai@thehai-Vostro-3550:~/my-project$ touch readme
thehai@thehai-Vostro-3550:~/my-project$ git add readme
thehai@thehai-Vostro-3550:~/my-project$ git commit -m "commit lan dau"
[master (root-commit) 391f79f] commit lan dau
 0 files changed
 create mode 100644 readme
thehai@thehai-Vostro-3550:~/my-project$ git remote add origin ssh://git@192.168.1.14/~/my-project.git
thehai@thehai-Vostro-3550:~/my-project$ git status
# On branch master
nothing to commit (working directory clean)
thehai@thehai-Vostro-3550:~/my-project$ git push -u origin master
Agent admitted failure to sign using the key.
git@192.168.1.14's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 206 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://git@192.168.1.14/~/my-project.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
thehai@thehai-Vostro-3550:~/my-project$ git status
# On branch master
nothing to commit (working directory clean)


Hẹn gặp lại:D
https://www.digitalocean.com/community/articles/how-to-set-up-a-private-git-server-on-a-vps

2 nhận xét:

  1. chmod 700 .ssh/
    chmod 600 .ssh/authorized_keys

    Trả lờiXóa
  2. Để đẩy dữ liệu lên server dùng lệnh:
    $ git push origin master

    Để kéo dữ liệu về :
    $ git pull origin master

    LƯU Ý: TRước khi kéo hay đẩy phải commit nó trc

    Trả lờiXóa

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.