哪些網(wǎng)站可以做外部錨文本seo營(yíng)銷(xiāo)推廣全程實(shí)例
目錄
- 一、基本信息
- 1.1 系統(tǒng)信息
- 1.2 git版本[^1]
- 1.2.1 服務(wù)器端git版本
- 1.2.2 客戶端TortoiseGit版本
- 1.2.3 客戶端Git for windows版本
- 二、創(chuàng)建git用戶和群組[^2]
- 2.1 使用groupadd創(chuàng)建群組
- 2.2 創(chuàng)建git用戶
- 2.2.1 使用useradd創(chuàng)建git用戶
- 2.2.2 配置新建的git用戶ssh免密訪問(wèn)
- 2.3 創(chuàng)建git倉(cāng)庫(kù)文件夾
- 2.4 切換到項(xiàng)目文件夾初始化git倉(cāng)庫(kù)
- 三、配置權(quán)限
- 3.1 直接使用zero賬戶訪問(wèn)
- 3.2 通過(guò)gpasswd設(shè)置git倉(cāng)庫(kù)權(quán)限
- 3.3 設(shè)置git_user的權(quán)限
- 3.4 禁止git_user通過(guò)ssh登錄服務(wù)器
一、基本信息
1.1 系統(tǒng)信息
zero@ubuntu:~$ uname -a
Linux ubuntu 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
1.2 git版本1
1.2.1 服務(wù)器端git版本
zero@ubuntu:~$ git --version
git version 2.34.1
1.2.2 客戶端TortoiseGit版本
1.2.3 客戶端Git for windows版本
$ git --version
git version 2.38.1.windows.1
二、創(chuàng)建git用戶和群組2
2.1 使用groupadd創(chuàng)建群組
zero@ubuntu:~$ sudo groupadd git # 創(chuàng)建git群組
[sudo] password for zero:
zero@ubuntu:~$ getent group git # 查詢git群組信息
git:x:1001:
2.2 創(chuàng)建git用戶
2.2.1 使用useradd創(chuàng)建git用戶
zero@ubuntu:/etc/ssh$ sudo useradd -m -g git git_user # 創(chuàng)建用戶,并指定初始區(qū)組為git,創(chuàng)建家目錄
zero@ubuntu:~$ id git_user # 查詢用戶基本信息
uid=1001(git_user) gid=1001(git) groups=1001(git)
zero@ubuntu:/etc/ssh$ sudo passwd git_user # 修改用戶密碼,不修改密碼,可能后續(xù)ssh無(wú)法登錄
New password:
Retype new password:
passwd: password updated successfully
此處創(chuàng)建用戶的時(shí)候就指定初始群組為git了,亦可以先行創(chuàng)建用戶,然后通過(guò)gpasswd將用戶添加到創(chuàng)建的git群組中。
2.2.2 配置新建的git用戶ssh免密訪問(wèn)
因?yàn)閟sh的文件存儲(chǔ)的是在配置用戶家目錄的.ssh文件夾下,所以新建的用戶并不能直接使用管理用戶之前配置的ssh密鑰,需要重新配置ssh配置才可正常使用。
zero@ubuntu:~$ sudo cp .ssh/authorized_keys /home/git_user/.ssh/authorized_keys # 拷貝密鑰文件到新用戶家目錄下zero@ubuntu:~$ sudo chown -R git_user /home/git_user/.ssh/authorized_keys # 修改擁有者
[sudo] password for zero:
zero@ubuntu:~$ sudo chgrp -R git /home/git_user/.ssh/authorized_keys # 修改擁有者群組
zero@ubuntu:~$ sudo getfacl /home/git_user/.ssh/authorized_keys# 查詢文件權(quán)限
getfacl: Removing leading '/' from absolute path names
# file: home/git_user/.ssh/authorized_keys
# owner: git_user
# group: git
user::rw-
group::---
other::---
2.3 創(chuàng)建git倉(cāng)庫(kù)文件夾
# 創(chuàng)建文件夾,可以根據(jù)自己需求創(chuàng)建文件夾,一般項(xiàng)目文件放置到mnt目錄下
# 不要在根目錄直接創(chuàng)建倉(cāng)庫(kù)文件夾,否則,由于權(quán)限問(wèn)題,git會(huì)無(wú)法訪問(wèn)到倉(cāng)庫(kù)。
zero@ubuntu:~$ sudo mkdir /mnt/git # 切換到倉(cāng)庫(kù)文件夾中,創(chuàng)建項(xiàng)目文件夾
zero@ubuntu:~$ cd /mnt/git
zero@ubuntu:/mnt/git$ ll
total 8
drwxr-xr-x 2 root root 4096 Sep 9 22:16 ./
drwxr-xr-x 3 root root 4096 Sep 9 22:16 ../zero@ubuntu:/mnt/git$ sudo mkdir testproject
zero@ubuntu:/mnt/git$ ll
total 12
drwxr-xr-x 3 root root 4096 Sep 9 22:16 ./
drwxr-xr-x 3 root root 4096 Sep 9 22:16 ../
drwxr-xr-x 2 root root 4096 Sep 9 22:16 testproject/
小插曲,苦于每次sudo都要輸入密碼,所以將zero賬戶的默認(rèn)群組改成sudo,同時(shí)將賬戶添加到root群組中,省去每次sudo都需要輸入密碼。
# 實(shí)測(cè)過(guò)程中,發(fā)現(xiàn)此操作可以解決一部分,不過(guò)有的指令還是需要輸入密碼,后續(xù)再研究研究怎么處理。
zero@ubuntu:~$ sudo usermod -g sudo zero
zero@ubuntu:~$ id zero
uid=1000(zero) gid=27(sudo) groups=27(sudo),4(adm),24(cdrom),30(dip),46(plugdev),110(lxd)
zero@ubuntu:~$ sudo gpasswd -a zero root
Adding user zero to group root
2.4 切換到項(xiàng)目文件夾初始化git倉(cāng)庫(kù)
# 切換到項(xiàng)目文件夾
zero@ubuntu:~$ sudo mkdir /mnt/git # 初始化項(xiàng)目庫(kù),注意需要使用root權(quán)限,然后使用--bare參數(shù)
zero@ubuntu:/mnt/git/testproject$ git init --bare
/mnt/git/testproject/branches/: Permission denied
zero@ubuntu:/mnt/git/testproject$ sudo git init --bare
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /mnt/git/testproject/
可以查看下倉(cāng)庫(kù)的權(quán)限,具體如下:
zero@ubuntu:/mnt/git/testproject$ cd ..
zero@ubuntu:/mnt/git$ ll testproject
total 40
drwxr-xr-x 7 root root 4096 Sep 9 22:21 ./
drwxr-xr-x 3 root root 4096 Sep 9 22:16 ../
drwxr-xr-x 2 root root 4096 Sep 9 22:21 branches/
-rw-r--r-- 1 root root 66 Sep 9 22:21 config
-rw-r--r-- 1 root root 73 Sep 9 22:21 description
-rw-r--r-- 1 root root 23 Sep 9 22:21 HEAD
drwxr-xr-x 2 root root 4096 Sep 9 22:21 hooks/
drwxr-xr-x 2 root root 4096 Sep 9 22:21 info/
drwxr-xr-x 4 root root 4096 Sep 9 22:21 objects/
drwxr-xr-x 4 root root 4096 Sep 9 22:21 refs/
可以看出目前權(quán)限為root,需要手動(dòng)配置權(quán)限,用戶才能正常訪問(wèn)。
三、配置權(quán)限
3.1 直接使用zero賬戶訪問(wèn)
由于創(chuàng)建的項(xiàng)目權(quán)限有的文件權(quán)限不足,我們就先給他修改下,給所有文件充足的權(quán)限,先確保能正常訪問(wèn):
配置完之后倉(cāng)庫(kù)的默認(rèn)權(quán)限是root,我們使用zero賬戶可以訪問(wèn),如下:
若賬戶未通過(guò)2.2.2章節(jié)配置免密登錄時(shí),此時(shí)使用新建用戶無(wú)法下載,如下,一直卡著,無(wú)法克隆下來(lái)(下圖是win11系統(tǒng)沒(méi)有提示,換成win10系統(tǒng)后,會(huì)提示需要輸入密碼)
3.2 通過(guò)gpasswd設(shè)置git倉(cāng)庫(kù)權(quán)限
# 將git倉(cāng)庫(kù)的權(quán)限配置給git群組,-R表示所有子項(xiàng)目相同設(shè)置,-m表示設(shè)定后續(xù)參數(shù),g表示設(shè)置群組信息
zero@ubuntu:/mnt$ sudo setfacl -R -m g:git:rwx git
zero@ubuntu:/mnt$ ll git
total 12
drwxrwxr-x+ 3 root root 4096 Sep 9 22:16 ./
drwxr-xr-x 3 root root 4096 Sep 9 22:16 ../
drwxrwxr-x+ 7 root root 4096 Sep 9 22:21 testproject/
zero@ubuntu:/mnt$ getfacl git
# file: git
# owner: root
# group: root
user::rwx
group::r-x
group:git:rwx
mask::rwx
other::r-x
3.3 設(shè)置git_user的權(quán)限
多用戶使用時(shí),建議修改git群組的權(quán)限,不給git群組多余的權(quán)限,只提供指定項(xiàng)目文件夾的權(quán)限即可,這樣,新用戶只能有限的訪問(wèn)git項(xiàng)目,無(wú)法修改系統(tǒng)參數(shù)。
3.4 禁止git_user通過(guò)ssh登錄服務(wù)器
通過(guò)修改用戶的shell可以有效的管理用戶的登錄,只需要將用戶的shell設(shè)置為git-shell,即可限制用戶只能通過(guò)ssh拉取git庫(kù),但是無(wú)法通過(guò)ssh訪問(wèn)服務(wù)器。
zero@ubuntu:~$ sudo usermod -s /bin/git-shell git_user
[sudo] password for zero:
zero@ubuntu:~$ getent passwd git_user
git_user:x:1004:1004::/home/git_user:/bin/git-shell
修改后嘗試使用git賬戶訪問(wèn)服務(wù)器被拒絕了。
PS C:\WINDOWS\system32> ssh git_user@192.168.60.3
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-83-generic x86_64)* Documentation: https://help.ubuntu.com* Management: https://landscape.canonical.com* Support: https://ubuntu.com/advantageSystem information as of Wed Sep 13 01:09:10 AM UTC 2023System load: 0.31298828125 Processes: 222Usage of /: 37.5% of 9.75GB Users logged in: 1Memory usage: 12% IPv4 address for ens33: 192.168.60.3Swap usage: 0%* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8sjust raised the bar for easy, resilient and secure K8s cluster deployment.https://ubuntu.com/engage/secure-kubernetes-at-the-edgeExpanded Security Maintenance for Applications is not enabled.15 updates can be applied immediately.
3 of these updates are standard security updates.
To see these additional updates run: apt list --upgradableEnable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro statusLast login: Wed Sep 13 01:07:57 2023 from 192.168.60.1# 這里,因?yàn)間it-shell未啟動(dòng)所以報(bào)錯(cuò),然后直接關(guān)閉連接了
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to 192.168.60.3 closed.
PS C:\WINDOWS\system32>
注:這里我又做了下嘗試,將shell改成隨便編的“test-shell”,結(jié)果同樣無(wú)法登錄,而且變成無(wú)法免密登錄了,而且即使輸入正確的密碼也無(wú)法訪問(wèn),同時(shí)git也無(wú)法訪問(wèn)。
PS C:\WINDOWS\system32> ssh git_user@192.168.60.3
git_user@192.168.60.3's password:
Permission denied, please try again.
git_user@192.168.60.3's password:
Permission denied, please try again.
git_user@192.168.60.3's password:
git_user@192.168.60.3: Permission denied (publickey,password).
git倉(cāng)庫(kù)配置過(guò)程詳見(jiàn)Ubuntu Server搭建Git服務(wù)器 ??
關(guān)于ubuntu的用戶和群組管理可參考:Linux學(xué)習(xí)筆記-Ubuntu系統(tǒng)用戶、群組、權(quán)限管理 ??