This guide outlines how to quickly and securely set up a Git repository on your Local Area Network (LAN) for internal team collaboration. Here’s a step-by-step breakdown to help you work efficiently:
Before you begin, ensure you have:
Install Git: Use the following commands for different Linux distributions:
sudo apt-get install git -y
sudo dnf install git -y
sudo pacman -S git
To set up a repository, it’s recommended to create a dedicated Git user for better control over authentication.
Create Git User:
On the remote machine, create a Git user:
sudo adduser git
Set a strong password and answer the prompts.
2. Switch to the Git user:
su git
Navigate to the Git user’s home directory:
cd
Set Up SSH Directory:
Create the .ssh
directory:
mkdir .ssh
chmod 700 .ssh
2. Create the authorized_keys
file:
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
Add SSH Keys:
From the local machine, view the public key:
cat /home/USER/.ssh/id_rsa.pub
If you don’t have SSH keys, generate them with:
ssh-keygen
2. Copy the public key and add it to the remote machine:
nano /home/git/.ssh/authorized_keys
Paste the copied content into the file and save.
Create and Initialize Repository:
mkdir /home/git/repository
cd /home/git/repository
mkdir my_project
cd my_project
Initialize a bare repository to allow collaboration:
git init --bare --shared
On your local machine, clone the new repository using:
git clone git@SERVER:/home/git/repository/my_project
Where SERVER
is the IP address or hostname of the remote machine.
Verify the remote repository:
git remote -v
Add and Push Changes:
README
file in the local clone:
nano README
Add any desired content, then stage and commit the changes:
git add --all
git commit -m "Added README file"
git push origin master
2. Verify changes on the remote machine:
nano /home/git/repository/my_project/README
Pull Changes: From the local machine, pull the changes to update:
git pull
To allow other team members access, add their public SSH keys to the authorized_keys
file of the Git user.
Setting up a Git repository on a LAN provides a quick, secure, and cost-effective way for your team to collaborate on a project. By following the steps outlined above, you can establish a fully functioning Git environment without relying on external hosting services like GitHub, making it ideal for internal, temporary, or isolated projects.