在 Mac OS 上設置 Git Server

使用 public key 作認證

丁叮盯町
3 min readSep 16, 2020

Mac OS 自帶 Git,因此關於 Git 的安裝就不多說了。

所有的操作都在 Client 端完成,對 Server 的操作是使用使用 SSH 連線至遠端。

首先,在 Client 產生一組 ssh rsa 公鑰。
公鑰的預設路徑是:/Users/{Your_Name}/.ssh/id_rsa.pub

ssh-keygen -t rsa

將產生的公鑰 copy 到 Server

scp /Users/username/.ssh/id_rsa.pub username@10.34.70.153:.ssh/authorized_keys

接下來要修改 Server 上的 sshd_config
先修改 sshd_config 的存取權限

ssh username@10.34.70.153
cd /etc/ssh
sudo chmod 666 sshd_config

編輯 sshd_config 的設定內容

vi sshd_config

把 PermitRootLogin 前的 ‘#’ 拿掉,並且把 ‘yes’ 改成 ‘no’

#PermitRootLogin yes change to PermitRootLogin no

把以下設定參數前的 ‘#’ 拿掉

#Remove the following ‘#’:#RSAAuthentication yes
# AuthorizedKeysFile .ssh/authorized_keys
# PasswordAuthentication no
# PermitEmptyPasswords no

把 UsePAM 前的 ‘#’ 拿掉,並且把 ‘yes’ 改成 ‘no’

#UsePAM yes change to UsePAM no

改完之後儲存並離開

在 Server 創建一個空的儲存庫

cd /Users/username/Documents
mkdir repo.git #create your own name
cd repo.git
git init — bare

在 Client 端,建一個 local repository,並且做 initial commit

cd /Users/{Your_Name}/Documents
mkdir newRepo
cd /Users/{Your_Name}/Documents/newRepo
git init
touch README
git add
git commit -m “initial commit”
git remote add origin username@10.34.70.153:Documents/repo.git

--

--

丁叮盯町
0 Followers

單純的程序猿,想寫些什麼記錄生活、記錄所學