You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 16.04本地Git服务器搭建及同网客户端配置步骤与命令

Ubuntu 16.04 Local Git Server Setup & Client Fixes

Hey there, let's get your local Git server up and running smoothly on Ubuntu 16.04, and make sure your client connects without issues. I've walked through this process dozens of times, so let's break it down into clear, actionable steps.

Server-Side Setup (Ubuntu 16.04)

1. Install Git on the Server

First, update your package list and install Git:

sudo apt-get update && sudo apt-get install git -y

2. Create a Dedicated Git User

For security, it's best to use a separate user for Git operations instead of your main account. Create the user and set a password when prompted:

sudo adduser git

3. Configure SSH Key Authentication (Skip Password Prompts)

Password-based auth is less secure and annoying to use. Set up key-based access:

  • Switch to the git user:
    sudo su - git
    
  • Create the SSH directory and set strict permissions (critical for SSH to work):
    mkdir ~/.ssh && chmod 700 ~/.ssh
    touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys
    
  • Now, from your client machine, generate an SSH key (if you don't have one):
    ssh-keygen -t rsa -b 4096
    
  • Copy the client's public key to the server's authorized_keys file. The easiest way is:
    ssh-copy-id git@your-server-ip
    
    Replace your-server-ip with the actual IP address of your Git server.

4. Create a Bare Git Repository

A bare repository has no working directory—it's designed solely for sharing and pushing/pulling changes. Let's create one:

  • Still as the git user, make a directory to store your repositories:
    mkdir -p /home/git/repos
    
  • Navigate to the repo directory and initialize the bare repo:
    cd /home/git/repos
    git init --bare my-project.git
    
    Replace my-project.git with your actual project name.

Client-Side Setup (Ubuntu 16.04)

1. Install Git on the Client

If you haven't already, install Git on your client machine:

sudo apt-get update && sudo apt-get install git -y

2. Clone the Repository & Test Basic Operations

Now connect to the server and clone the repo:

git clone git@your-server-ip:/home/git/repos/my-project.git

Once cloned, test pushing a commit to make sure everything works:

cd my-project
echo "Test file" > test.txt
git add test.txt
git commit -m "First test commit"
git push origin master

Troubleshooting Common Issues

If you were having problems before, check these common fixes:

  • Permission Errors: Ensure the git user owns the repository directory:
    sudo chown -R git:git /home/git/repos
    
  • SSH Connection Failures: Verify SSH settings on the server:
    1. Open the SSH config file:
      sudo nano /etc/ssh/sshd_config
      
    2. Make sure these lines are uncommented and set correctly:
      PubkeyAuthentication yes
      PasswordAuthentication yes  # Optional, keep if you want password fallback
      
    3. Restart the SSH service:
      sudo systemctl restart ssh
      
  • Firewall Blocking: If you're using UFW, ensure port 22 (SSH) is open:
    sudo ufw allow ssh
    

内容的提问来源于stack exchange,提问作者Jijo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:19:43