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

git-secret 使用教程

以下是一份详细的 git-secret 使用教程,包含常见场景的 Bash 代码示例:


1. 安装 git-secret

# Ubuntu/Debian
sudo apt-get install git-secret

# macOS (Homebrew)
brew install git-secret

# 其他 Linux (Snap)
sudo snap install git-secret

# 验证安装
git secret --version

2. 初始化仓库

cd your-git-repo
git secret init  # 创建 .gitsecret 目录

3. 生成 GPG 密钥(如果尚未生成)

gpg --gen-key  # 按提示生成密钥
gpg --list-secret-keys  # 查看生成的密钥

4. 基本场景:个人加密/解密

# 添加自己为可信用户(需使用GPG邮箱)
git secret tell your-email@example.com

# 添加要加密的文件
git secret add api-keys.txt

# 加密文件(生成 api-keys.txt.secret)
git secret hide

# 解密文件(需GPG私钥)
git secret reveal

5. 团队协作场景

# 添加团队成员(需他们的GPG公钥)
# 先导入对方的公钥
gpg --import teammate.pub

# 然后添加到git-secret
git secret tell teammate@company.com

# 重新加密所有文件
git secret hide

6. CI/CD 自动解密

# 在 CI 环境中设置 GPG 私钥
echo "$GPG_PRIVATE_KEY" | gpg --import
echo "passphrase" > /tmp/passphrase.txt

# 解密文件(非交互模式)
git secret reveal -p /tmp/passphrase.txt

# 安全清理
shred -u /tmp/passphrase.txt

7. 管理多个文件

# 添加多个文件
git secret add config/*.env

# 加密所有已添加文件
git secret hide

# 查看被管理的文件列表
git secret list

# 移除某个文件
git secret remove api-keys.txt

8. 用户权限管理

# 查看所有有权限的用户
git secret whoknows

# 移除用户权限
git secret killperson old-teammate@company.com

# 更新所有文件权限
git secret hide

9. 高级用法:修改密码

# 生成新密钥对
gpg --gen-key

# 添加新密钥到git-secret
git secret tell new-email@example.com

# 重新加密文件
git secret hide

10. 最佳实践

  1. .gitignore 配置: 确保在 .gitignore 中添加:

    echo "*.secret" >> .gitignore
    echo "!*.secret" >> .gitsecret/keys
    
  2. 密钥备份: 导出备份密钥:

    gpg --export-secret-keys -a your-email@example.com > backup-private.key
    
  3. 审计日志: 查看加密历史:

    git log --oneline --graph --decorate --name-only -- **/*.secret
    

常见问题排查

# 解密失败时检查密钥匹配
gpg --list-secret-keys

# 清除 GPG 代理缓存
gpgconf --kill gpg-agent

# 强制重新加密所有文件
git secret hide -f

记得在协作场景中定期更换密钥!


http://www.kler.cn/a/532618.html

相关文章:

  • 读写锁: ReentrantReadWriteLock
  • STM32F103ZET6完整技术点(持续更新~)
  • Spark的基本概念
  • XCCL、NCCL、HCCL通信库
  • 【C++】P1765 手机
  • deep generative model stanford lecture note3 --- latent variable
  • JVM- 垃圾回收算法
  • Leetcode922: 按奇偶排序数组 II
  • [Go]一、Go语言基础
  • 基于 docker 的mysql 5.7 主主集群搭建
  • fpga系列 HDL:XILINX Vivado ZYNQ-7000 PS-PL数据交互 AXI4 实现笔记
  • ros 发布Topic
  • 【力扣】238.除自身以外数组的乘积
  • Rust HashMap :当储物袋遇上物品清单
  • 基于CY8CKIT-149 BLE HID设备实现及PC控制功能开发(BLE HID+CapSense)
  • ELF2开发板(飞凌嵌入式)搭建深度学习环境部署(RKNN环境部署)
  • 4种架构的定义和关联
  • 数据结构——并查集
  • 【单层神经网络】softmax回归的从零开始实现(图像分类)
  • gesp(C++六级)(8)洛谷:P10377:[GESP202403 六级] 好斗的牛
  • 【C++】泛型编程:吃透模板
  • 2023 年 12 月大学英语四级考试真题(第 3 套)——纯享题目版
  • 线性回归原理和算法
  • Verilog基础(四):组合逻辑
  • 深度求索DeepSeek横空出世
  • Swift语言的文件操作