当前位置: 首页 > news >正文

照片展示网站模板免费下载备案网站建设方案书范文

照片展示网站模板免费下载,备案网站建设方案书范文,网站建设网站软件,杭州做美妆的网站目录 一、基本信息1.1 系统信息1.2 git版本[^1]1.2.1 服务器端git版本1.2.2 客户端TortoiseGit版本1.2.3 客户端Git for windows版本 二、创建git用户和群组[^2]2.1 使用groupadd创建群组2.2 创建git用户2.2.1 使用useradd创建git用户2.2.2 配置新建的git用户ssh免密访问 2.3 创…

目录

  • 一、基本信息
    • 1.1 系统信息
    • 1.2 git版本[^1]
      • 1.2.1 服务器端git版本
      • 1.2.2 客户端TortoiseGit版本
      • 1.2.3 客户端Git for windows版本
  • 二、创建git用户和群组[^2]
    • 2.1 使用groupadd创建群组
    • 2.2 创建git用户
      • 2.2.1 使用useradd创建git用户
      • 2.2.2 配置新建的git用户ssh免密访问
    • 2.3 创建git仓库文件夹
    • 2.4 切换到项目文件夹初始化git仓库
  • 三、配置权限
    • 3.1 直接使用zero账户访问
    • 3.2 通过gpasswd设置git仓库权限
    • 3.3 设置git_user的权限
    • 3.4 禁止git_user通过ssh登录服务器

一、基本信息

1.1 系统信息

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 服务器端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

二、创建git用户和群组2

2.1 使用groupadd创建群组

zero@ubuntu:~$ sudo groupadd git	# 创建git群组
[sudo] password for zero:
zero@ubuntu:~$ getent group git		# 查询git群组信息
git:x:1001:

2.2 创建git用户

2.2.1 使用useradd创建git用户

zero@ubuntu:/etc/ssh$ sudo useradd -m -g git git_user		# 创建用户,并指定初始区组为git,创建家目录
zero@ubuntu:~$ id git_user						# 查询用户基本信息
uid=1001(git_user) gid=1001(git) groups=1001(git)
zero@ubuntu:/etc/ssh$ sudo passwd git_user		# 修改用户密码,不修改密码,可能后续ssh无法登录
New password:
Retype new password:
passwd: password updated successfully

此处创建用户的时候就指定初始群组为git了,亦可以先行创建用户,然后通过gpasswd将用户添加到创建的git群组中。

2.2.2 配置新建的git用户ssh免密访问

因为ssh的文件存储的是在配置用户家目录的.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# 查询文件权限
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 创建git仓库文件夹

# 创建文件夹,可以根据自己需求创建文件夹,一般项目文件放置到mnt目录下
# 不要在根目录直接创建仓库文件夹,否则,由于权限问题,git会无法访问到仓库。
zero@ubuntu:~$ sudo mkdir /mnt/git	# 切换到仓库文件夹中,创建项目文件夹
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账户的默认群组改成sudo,同时将账户添加到root群组中,省去每次sudo都需要输入密码。

# 实测过程中,发现此操作可以解决一部分,不过有的指令还是需要输入密码,后续再研究研究怎么处理。
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 切换到项目文件夹初始化git仓库

# 切换到项目文件夹
zero@ubuntu:~$ sudo mkdir /mnt/git	# 初始化项目库,注意需要使用root权限,然后使用--bare参数		
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/

可以查看下仓库的权限,具体如下:

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/

可以看出目前权限为root,需要手动配置权限,用户才能正常访问。

三、配置权限

3.1 直接使用zero账户访问

由于创建的项目权限有的文件权限不足,我们就先给他修改下,给所有文件充足的权限,先确保能正常访问:
配置完之后仓库的默认权限是root,我们使用zero账户可以访问,如下:
在这里插入图片描述
若账户未通过2.2.2章节配置免密登录时,此时使用新建用户无法下载,如下,一直卡着,无法克隆下来(下图是win11系统没有提示,换成win10系统后,会提示需要输入密码)
在这里插入图片描述

3.2 通过gpasswd设置git仓库权限

# 将git仓库的权限配置给git群组,-R表示所有子项目相同设置,-m表示设定后续参数,g表示设置群组信息
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 设置git_user的权限

多用户使用时,建议修改git群组的权限,不给git群组多余的权限,只提供指定项目文件夹的权限即可,这样,新用户只能有限的访问git项目,无法修改系统参数。

3.4 禁止git_user通过ssh登录服务器

通过修改用户的shell可以有效的管理用户的登录,只需要将用户的shell设置为git-shell,即可限制用户只能通过ssh拉取git库,但是无法通过ssh访问服务器。

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账户访问服务器被拒绝了。

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# 这里,因为git-shell未启动所以报错,然后直接关闭连接了
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”,结果同样无法登录,而且变成无法免密登录了,而且即使输入正确的密码也无法访问,同时git也无法访问。

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).

  1. git仓库配置过程详见Ubuntu Server搭建Git服务器 ↩︎

  2. 关于ubuntu的用户和群组管理可参考:Linux学习笔记-Ubuntu系统用户、群组、权限管理 ↩︎

http://www.yayakq.cn/news/95464/

相关文章:

  • 建设信用交通网站 省wordpress上传慢
  • 教务系统网站怎么做wap网站源码下载
  • 建网站教学视频南昌专业制作网站
  • 外贸网站建设开发网站建设市场分析2015
  • 百度移动端网站网络营销的五个特点
  • 网站pc开发上海网站备案企业用个人来备案可以用吗
  • 电商网站的分辨率引流推广方式
  • 重庆网站建设挑夹夹虫兰州市一地发布提醒
  • 大庆免费网站建设公司百度智能建站平台
  • 英语网站都可以做哪些内容长城宽带
  • 哪一个做h5的网站好济南做网站互联网公司有哪些
  • 提升网站权重的方法自己做的网站出现广告
  • 如何添加网站白名单什么是网页浏览器
  • 狗铺子做网页在那个网站wordpress插件cloud
  • 网站建设的背景有哪些深圳谷歌推广公司
  • 网站团队人数重庆森林经典台词
  • 网站地址格式网络广告公司怎么做
  • 东莞整合网站建设推广网络销售就是忽悠人
  • 如何加强高校网站建设郑州网站建设最便宜
  • 建网站容易吗做网站商城
  • 广东省企网站建设关于建设 网站的请示
  • 代点任意广告链接网站灞桥微网站建设
  • 大连住房城乡建设网站手机网站建设的行情
  • 邯郸哪里制作网站关键词查询网站的工具
  • 网站根据城市做二级目录爱做网站外国
  • 北京建设官方网站穹拓做网站
  • 建站不用域名直接用ip可以吗郑州网站 建设
  • 投诉举报网站 建设方案丹东建设网站
  • 网站文字专题页面怎么做的python 网站开发
  • 浅谈博物馆网站的建设意义做系统的网站