♠ Posted by NN TRUNG at 18:09
In some instances, you may not want to upgrade your account at Repository Hosting services from free to pay to be able to create unlimited source code repository, which you want to Give yourself a comfortable Repository Server to create as many repositories are. Indeed, with only $ 5 / month to rent a VPS Linux inDigitalOcean then you can create a good and sufficient Repository Server to use for your team from small to medium.
Prepared
A Linux Server, which can be any operating system but also the use of common operating systems and is easy to manipulate you, such as Ubuntu, CentOS, Debian, Fedora, ... And you must use the root user .
In this article, I will use the Ubuntu operating system 32-bits at DigitalOcean 14:04.
If you install the server, make sure that have installed SSH and open SSH port (default is 22).
Installing Git
First you install Git on the server with the command:
CentOS / RHEL / Fedora
$ Yum install git
Ubuntu / Debian
$ Apt-get install git
Then type git to check out the content guide, and if successful implementation.
Create Repository
Processes created in the Server Repository Reply repository like I wrote earlier. But for better safety, I encourage you to follow his steps.
Step 1. Create a user accessing the repository
This step we will create a user for the connection from the personal computer will use it and not connected directly to the root user offline.
Examples himself created a user named
git_user
and. $ Useradd git_user
Rare: In case when creating a user does not create its own folder for this user in / home / git_user then you can create handcrafted using the root account with the commandmkdir /home/git_user
and use thechown -R git_user:git_user /home/git_user
to grant this directory for user git_user.
And set the password for git_user with command
passwd git_user
, note that this password, you should only use your own user to access the remote repository git_user faster than in personal computers will use SSH for security no need to retype user / pass to push.
Reference: Administrative & Create user on Linux
Password settings done, type su - to turn over user git_user git_user and type cd ~ to return to the root of it to work (these operations are done on the user below this git_user).
Step 2. Set up SSH for git_user
This step we will setup allows external users connect to the directory / home / git_user using SSH protocol for security and convenience.
Reference: Security Server with SSH Key
Create this folder to the user .ssh.
$ Mkdir ~ / .ssh /
Next is creating authorized_keys file in the directory .ssh / of it.
$ Touch ~ / .ssh / authorized_keys
Now let CHMOD the folder ~ / .ssh / a 700.
$ Chmod 700 ~ / .ssh /
Then CHMOD 600 authorized_keys file.
$ Chmod 600 ~ / .ssh / authorized_keys
Step 2. Create a repository on a server
Make sure that you are accessing the user git_user and are the root of this user.
Now will create a file for repository .git with the command:
$ Git init --bare thachpham.git Git repository empty initialized in /home/git_user/thachpham.git/
Roài finished it.
Connect with computer repository
To connect to the repository thachpham.git that we just created, you must create an SSH private key and add it to the file in the folder .ssh authorized_keys of git_user.
To create SSH Key, open Terminal (or Git Bash in Windows) to and type the following command:
$ Ssh-keygen -t rsa -C "Key of jelly" Generating public / private rsa key pair. Enter to save the file chứa key (/home/thachpham/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification in /home/thachpham/.ssh/id_rsa Đã saved. Your public key saved in /home/thachpham/.ssh/id_rsa.pub Đã. The key fingerprint is: ce: 50: 14: df: 7b: 5e: a5: e2: 1f: 1e: af: 66: 79: 56: 57: 87 Key crab Thach The key's randomart image is: + - [RSA 2048] ---- + | O. | |. . . | |. . . .. | |. .E. + | |. S oo + | | +. + .o | | O. + .o | | O ++ o | | O ++. | + ----------------- +
Then at the computer, you type the command
cat ~/.ssh/id_rsa.pub
to see public key and copy it, then paste it into the authorized_keys file in the folder on the server /home/git_user/.ssh/. Note that each key will be a line if you add multiple key later on.
Afterwards, you can clone the repository on the server with the following command.
&& Git init $ git remote add origin git_user@123.456.78.9: thachpham.git Git repository empty initialized in /home/thachpham/thachpham_git/.git/
In it,
git_user
: user name on ownership git server folder you created123.456.78.9
: IP of serverthachpham.git
: repository name created on the server.
And now you can try to commit and push a file to the server.
$ Touch README.md $ Git add. $ Git commit -m "Initial commit" [Master (root-commit) 104f7b7] Initial commit 1 files changed, 0 insertions (+), 0 deletions (-) create mode 100644 README.md thachpham @ ubuntu: ~ / $ git push origin master thachpham_git Counting objects: 3, done. Writing objects: 100% (3/3), 215 bytes | 0 bytes / s, done. Total 3 (delta 0), reused 0 (delta 0) To git_user@46.101.154.122: thachpham.git * [New branch] master -> master
If you check the server, the repository directory will not see your files just push up. You can test this by creating another folder, then clone this repository on the file server you'll be towed.
Epilogue
Go here, you also have a clear grasp of how Git works, as well as knowing how to create a Git repository server for now? And this is the last article in this series and their basic Git hope that it can help you a lot in using Git. On video, I'll do later.
0 nhận xét:
Đăng nhận xét