Home >Development Tools >git >How to set up a github server on Linux

How to set up a github server on Linux

PHPz
PHPzOriginal
2023-03-31 14:02:191235browse

GitHub is the world's largest social networking site for programmers, where developers can collaborate on projects. In order to better collaborate and manage code, many programmers choose to build GitHub servers on their own servers. Below we will introduce how to set up a GitHub server on a Linux server.

Step one: Install Git

To build a GitHub server on a Linux server, you must first install Git. Use the following command to install Git:

sudo apt-get install git-core

After installation, you can use the following command to verify whether Git is installed successfully:

git --version

Step 2: Create a user

For better To manage the code, you can create a separate user for each collaborator. Create a user using the following command:

sudo adduser <username>

where username is the username you want to create. Then set the user password and follow the command prompts to complete the setting.

Step Three: Create SSH Keys

To ensure security and allow collaborators to push changes, we need to set up SSH keys on each user. First, we need to create an SSH key on each user.

To generate a key, use the following command:

ssh-keygen -t rsa -C "<email>"

email Fill in your email address.

Add the key to public access:

cd /home/<username>/.ssh
cp id_rsa.pub authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
sudo chown -R <username>:<username> ~/.ssh

Where home/ is the user's folder location.

Step 4: Create a repository

Create a new directory under your user directory and create a new repository for your new project:

mkdir /home/<username>/<project_name>.git
cd /home/<username>/<project_name>.git
git init --bare

Then change Permissions of the repository so that other users can also access it:

sudo chown -R <username>:<username> /home/<username>/<project_name>.git
sudo chmod -R ug+rwX /home/<username>/<project_name>.git

At this point you have successfully set up a GitHub server on the server, you can use the following commands to clone it on your computer, add changes and Push them back to the server:

git clone <username>@<serverip>:</home/<username>/<project_name>.git>

After modifying the code, you can push the code to the git server:

git add .
git commit -m "first commit code "
git push origin master

The above is a brief introduction to setting up a GitHub server on a Linux server. Hope this helps. You can adjust and improve it according to your needs.

The above is the detailed content of How to set up a github server on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn