When managing my own code, I always use github. Sometimes, private projects don't want to be public, if they want to put them on GitHub, then they have to spend money. The solution to this problem is actually very simple: run a server (CentOS) with a virtual machine (VirtualBox) on your computer, and configure ssh and git server. As the saying goes: the server closest to you in history.
SSH is a must-have for programmers to connect to the server at home! Therefore, after installing CentOS (minimal installation) in VirtualBox, the first job is to configure its SSH.
ssh-keygen -t rsa -C "[email protected]"
Pay attention to enter your own mailbox
You will be prompted to enter the password, but you can leave it blank (at least I leave it blank, it’s too much trouble to enter the password).
After completion, two key files, id_rsa
and id_rsa.pub
, will be generated in the .ssh
directory.
Pay attention to save these two files, even if you change the computer and redo the system, remember to back it up.
ip addr
as the picture shows:
ssh [email protected] -p 22
xxx.xxx.xxx.xxx is the ip address of CentOS, and you also need to enter the password of the root account of CentOS. The SSH login is used at this time to facilitate copying the key to authorized_keys.
CentOS
server in VirtualBox://create.ssh folder:
mkdir .ssh
//Create authorized_keys file:
touch .ssh/authorized_keys
//Modify authorized_Permission of keys:
chmod 600.ssh/authorized_keys
cat .ssh/id_rsa.pub
vi .ssh/authorized_keys
Set up port forwarding, as shown in the figure:
The above operation is to write the ip address as 127.0.0.1 when setting up alias login in the client (Mac), so as to avoid the automatic acquisition of ip changes every time CentOS is started, and it is too troublesome to modify.
vi .ssh/config
Enter the following:
Host cent
HostName 127.0.0.1
User root
Port 4444
cent is an alias, which can be set freely.
ssh cent
All operations can be performed on the client machine (Mac) by connecting to CentOS with SSH
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc perl-ExtUtils-MakeMaker
yum remove git
cd /usr/local
mkdir git
cd git
wget https://github.com/git/git/archive/v2.13.2.tar.gz
Up to now the latest version is 2.13.2, you can go to https://github.com/git/git/releases to copy the latest version link to download.
tar -xzvf v2.13.2.tar.gz
cd git-2.13.2
make prefix=/usr/local/git all
make prefix=/usr/local/git install
The compilation process is slightly longer, wait patiently
vi /etc/profile
Join
export PATH="/usr/local/git/bin:$PATH"
Make the configuration effective immediately
source /etc/profile
git --version
ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack
ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack
groupadd git
useradd git -g git
passwd git
Switch to git account
su -git
Create the
.ssh
directory and the.ssh/authorized_keys
file, and add the key in the id_rsa.pub of the client (Mac) to theauthorized_keys
file
Modify the permissions of directories and files
chmod 700.ssh
chmod 600.ssh/authorized_keys
cd /home/git
mkdir gitrepos
cd gitrepos
git init --bare test.git
Clone the test.git repository on CentOS on the client (Mac)
git clone git@cent:/gitrepos/test.git
cent
is the SSH connection alias of CentOS set in Chapter 2.3, and it can also be replaced with the corresponding ip address
If you are configuring a git server on a remote VPS server, for security reasons, you can prohibit Shell login; if, like the original intention of this article, it is to build the
the closest server in history
, then this step can be omitted.
Switch to the root account:
su
Edit the /etc/passwd
file:
vi /etc/passwd
Change this line:
git:x:502:502::/home/git:/bin/bash
Replace with:
git:x:502:502::/home/git:/usr/local/git/bin/git-shell
By using Virtualbox to build CentOS on this machine, it is convenient for developers to test; by building your own Git server on CentOS, you can manage and back up your independently developed code.
Recommended Posts