我正在公司环境中设置 git。Git 操作将主要通过 SSH 使用单个帐户进行,并使用 SSH 密钥进行访问控制。(http 将用于帐户配置、基于 Web 的代码浏览,但除此之外别无其他。)
但拥有永不过期的 SSH 密钥的想法对我来说听起来很愚蠢。只需要一台受感染的桌面即可泄露私钥,入侵者就可以永久访问我们的知识产权。
我已经进行了大量的谷歌搜索,但关于此的信息很少。这让我感到震惊,因为我不认为我走错了路。
定期使密钥过期很容易,尽管 GitLab 和 Stash 等工具并没有让这件事变得简单。我们有一个“ git login”包装脚本,用于将 SSH 公钥发送到服务器。它可以确保旧密钥不仅被重复使用,而且还可以确保使用特殊密钥(如 中指定的~/.ssh/config),以便我们不会定期覆盖某人的密钥~/.ssh/id_da*并阻止他们的其他登录。config(尽管对于我的一些 lon-linux (Windows) 用户来说,在 ssh 文件中指定的非默认位置使用密钥可能会出现问题。)
还有其他人这样做过吗?什么是行业最佳实践?
更新
好吧,看来部分答案是“这正是 SSH 密码的用途。” 所以剩下的问题是这样的
有没有办法强制使用和定期更改密码?我假设人们会遵守,只是需要对他们来说很容易。
而且,话虽如此,ssh 密码消除了在 cron 作业中执行 git 操作的能力。如果不能做到这一点,那将是一个真正的障碍。
当我使用时git clone https://my.example.com/gitlab/java/repository.git,我得到
克隆到“存储库”...
致命:无法访问“ https://my.example.com/gitlab/java/repository.git”:SSL证书问题:
无法获取本地颁发者证书
如果我设置的话效果很好git config --global http.sslVerify false
Gitlab 与 Apache2 和 SSL 一起使用,转发到 gitlab-workhorse。有关配置的更多详细信息:用于存储库克隆的 Gitlab HTTPS URI 不起作用 - SSL 主机无法验证 - 致命:无法访问
我尝试添加 SSL 证书,因为它们与 Apache 配置中的相同,但没有帮助:
nginx['ssl_certificate'] =“/etc/gitlab/ssl/my.example.com.crt”
nginx['ssl_certificate_key'] =“/etc/gitlab/ssl/my.example.com.key”
如何配置它以通过 HTTPS 进行 git 操作而不禁用验证?
Windows 10 现在包含内置的 sshd 服务器。这意味着我应该能够访问位于 Windows 计算机上的 git 存储库
git clone ssh://myid@mywinmachine/myrepos/repo1.git
Run Code Online (Sandbox Code Playgroud)
但是,上面的方法不起作用。我正进入(状态
fatal: ''/myrepos/repo1.git'' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
我认为问题是,mywinmachine 上的 git 存储库的目录位置存在混乱。
我不知道如何解决这个问题。我的 git 存储库位于 mywinmachine 上的 c:\myrepos\repo1.git (它实际上在另一个位置,但我创建了一个连接)。(我还尝试在 c:\users\myid\myrepos 处建立符号链接(连接点)——也没有帮助。)
当我执行 ssh myid@mywinmachine 时,一切正常。我登录正常,并且被放入 c:\users\myid 机器(进入 cmd 提示符)。
我在 mywinmachine 上设置了 Git Windows,这样就可以从任何命令提示符访问任何 git 命令。因此,在 mywinmachine 上,如果我输入: git --version,我会得到正确的响应
myid@mywinmachine C:\Users\myid>git --version
git version …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我们的 Gitlab 存储库克隆到 Docker 容器中,并在运行 Ubuntu 18.04.1 的新虚拟机上运行。
Cloning into ${REPONAME}由于某种原因,当我尝试克隆存储库时,在我们最终开始枚举对象之前,我花了很长时间(几分钟)进行查看。
time git clone https://gitlab.com/gnutls/gnutls.git
Cloning into 'gnutls'...
remote: Enumerating objects: 178256, done.
remote: Counting objects: 100% (178256/178256), done.
remote: Compressing objects: 100% (50440/50440), done.
remote: Total 178256 (delta 128831), reused 173620 (delta 125853)
Receiving objects: 100% (178256/178256), 66.50 MiB | 10.14 MiB/s, done.
Resolving deltas: 100% (128831/128831), done.
real 5m 2.14s
user 0m 14.42s
sys 0m 4.39s
Run Code Online (Sandbox Code Playgroud)
我决定尝试克隆一个不同的存储库,google test该存储库托管在 Github 上,差异令人震惊。
time git clone https://github.com/google/googletest.git
Cloning …Run Code Online (Sandbox Code Playgroud) 编辑:事实证明这是一个 Gitlab 问题,但我仍然没有解决方案。
\n\n我的两个 AWS EC2 实例出现了奇怪的情况。它们在操作系统、区域和实例类型(均为 t3.micro)方面完全相同,设置方式也相同(但是,第一个是在几个月前设置的)。
\n\n两者都存在于 eu-central-1c 可用区中,并且都在同一个 git 存储库上运行。两者也都是最新的(CentOS 7.6.1810)。
\n\n较旧的服务器:
\n\n$ time git pull\nAlready up-to-date.\n\nreal 0m0.306s\nuser 0m0.034s\nsys 0m0.016s\nRun Code Online (Sandbox Code Playgroud)\n\n较新的服务器:
\n\n$ time git pull\nAlready up-to-date.\n\nreal 2m7.547s\nuser 0m0.026s\nsys 0m0.024s\nRun Code Online (Sandbox Code Playgroud)\n\n它也始终需要大约 2 分 7 秒。
\n\n还:
\n\n较旧的服务器:
\n\n--2019-04-09 10:52:03-- https://speed.hetzner.de/1GB.bin\nResolving speed.hetzner.de (speed.hetzner.de)... 88.198.248.254, 2a01:4f8:0:59ed::2\nConnecting to speed.hetzner.de (speed.hetzner.de)|88.198.248.254|:443... connected.\nHTTP request sent, awaiting response... 200 OK\nLength: 1048576000 (1000M) [application/octet-stream]\nSaving to: \xe2\x80\x981GB.bin\xe2\x80\x99\n\n100%[===============================================================>] 1,048,576,000 121MB/s in 6.5s \n\n2019-04-09 10:52:10 (154 MB/s) - …Run Code Online (Sandbox Code Playgroud) 我想从本地 git 存储库中清理一个大文件(顺便清理我的存储库以减小大小)。这是我的狂欢:
#!/bin/bash
bigfile="/path_to_mygitproject/bigfile.tar.gz"
git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch '"$bigfile"'' --prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch '"$bigfile"'' HEAD
Run Code Online (Sandbox Code Playgroud)
但现在显示以下警告:
WARNING: git-filter-branch has a glut of gotchas generating mangled history
rewrites. Hit Ctrl-C before proceeding to abort, then use an
alternative filtering tool such as 'git filter-repo'
(https://github.com/newren/git-filter-repo/) instead. See the
filter-branch manual page for more details; to squelch this warning,
set FILTER_BRANCH_SQUELCH_WARNING=1.
Run Code Online (Sandbox Code Playgroud)
我一直用这个bash,从来没有遇到过问题。到目前为止。我猜 git 中发生了一些变化。
我尝试将“git filter-branch”替换为“git …
在尝试使用 SSH 克隆远程 Git 存储库时,我收到以下错误:
git clone user@remote-repo:project.git .
remote: Counting objects: 187444, done.
remote: Compressing objects: 100% (73430/73430), done.
client_loop: send disconnect: Broken pipe.06 MiB | 4.04 MiB/s
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: index-pack failed
Run Code Online (Sandbox Code Playgroud)
我的环境具有以下规格:
git --version git version 2.30.1git 包可以在这里找到https://pkgs.alpinelinux.org/package/edge/main/x86_64/git
uname -a
Linux 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 Linux
2021-03-09-07:11AM wsl@Alpine:~$ more /etc/issue
Welcome to Alpine Linux 3.10
Kernel \r …Run Code Online (Sandbox Code Playgroud) 为了自动为我所有的 git 存储库提供服务,http.conf 是什么?
例如,如果我有一个如下的目录结构(一个名为 git 的中央目录中的多个项目):
/../htdocs/git/project1
/../htdocs/git/project2
/../htdocs/git/project3
为了避免对每个项目重复相同的内容,我必须写什么:
<Location /git/project1>
DAV on
AuthType Basic
AuthName "Git"
AuthUserFile /../htdocs/git/project1/passwd.git
Require valid-user
</Location>
Run Code Online (Sandbox Code Playgroud)
奖金问题:
有没有办法将 repos 放在 apache 的 htdocs 之外的某个地方并将请求重定向到那里?(比如使用 DocumentRoot)
笔记:
所有存储库都是 --bare 因为它们是中央存储库(Trac 使用)
是否可以在给定的存储库中搜索字符串(例如“类名”)?
即使是长时间的操作,这对我来说也很有用。
感谢帮助!