afk11 / git-deploy-key
管理多个 git 部署密钥的实用工具
Requires
- afk11/ecssh: ~0.1
- paragonie/random_compat: ~2.0
- symfony/console: v3.0.*
This package is auto-updated.
Last update: 2024-08-23 05:39:11 UTC
README
这个 CLI 应用程序简化了为 git 仓库生成部署密钥的过程。
背景
Git 允许用户使用 SSH 公钥进行身份验证。虽然这比密码认证更优越,但大多数用户通常只在其环境中使用单个 SSH 密钥。
理想的情况是,为每个仓库和部署使用唯一的密钥,并使用完全不同的密钥登录机器。
如何工作
此应用程序生成适合 SSH 的 ECDSA 密钥。创建后,必须在远程 git 服务器上授予密钥访问权限。GitHub 有一个用于此目的的仓库设置 - GitHub 用户将被引导到此页面。
密钥保存在文件夹 ~/.ssh/gitdeploy
中。每个仓库在 ~/.ssh/config
中都有自己的条目,指定主机名、用户/域名/端口和密钥文件。
密钥使用默认 SSH 程序进行加密(加盐密码,通过 md5 单次遍历生成密钥)。PKCS#8 编码在待办事项列表中,因为它允许扩展加密密钥材料。
此工具通过设置 --no-password 选项支持未加密的密钥。
用法
安装工具
此工具通过 composer 提供。以下命令将应用程序保存到全局 composer 目录 (~/.composer)
composer global require afk11/git-deploy-key
更新您的 $PATH 以包括 ~/.composer/vendor/bin
echo "export PATH=~/.composer/vendor/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc # this is done automatically when you log in
在此阶段,您可以在任何地方使用此工具
git-deploy-key help
您还可以检出此仓库,并在运行 composer install
后在 bin/
目录中访问可执行文件
创建受密码保护的 SSH 密钥
创建密钥
user@dev:~$ git-deploy-key create git@github.com:Bit-Wasp/bitcoin-php
Confirm details:
[output trimmed]
Is this ok [y/n]: y
Password:
Password again:
You're using Github! You can paste the key in here: https://github.com/Bit-Wasp/bitcoin-php/settings/keys
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFz53QOkzt6ZPP1hnHY5iDqcGgLho2eZQe0h0SsAWwiwiGwT3bv6HRkKIeFeonWEH/j/QOpZee+5UyVBcMbM0Es= user@dev
Saved key to disk
克隆项目
user@dev:~/git$ git clone github-Bit-Wasp-bitcoin-php:Bit-Wasp/bitcoin-php
Cloning into 'bitcoin-php'...
Enter passphrase for key '/home/user/.ssh/gitdeploy/github-Bit-Wasp-bitcoin-php':
[output trimmed]
会话自定义名称
每个会话的默认名称由域名、组织和仓库组成。可以通过提供第二个参数来指定自定义名称。
$ git-deploy-key create git@github.com:Bit-Wasp/bitcoin-php gitbitcoin
$ git clone gitbitcoin:Bit-Wasp/bitcoin-php
未受保护的 SSH 密钥
可以设置 --no-password
选项来禁用密钥的加密。这在自动部署和计划更新期间很有用。
user@dev:~$ git-deploy-key create git@github.com:Bit-Wasp/bitcoin-p2p-php --no-password
Confirm details:
Private key file: /home/user/.ssh/gitdeploy/github-Bit-Wasp-bitcoin-p2p-php
Public key file: /home/user/.ssh/gitdeploy/github-Bit-Wasp-bitcoin-p2p-php.pub
The following config entry will be written:
Host github-Bit-Wasp-bitcoin-p2p-php
Hostname github.com
User git
Port 22
IdentityFile /home/user/.ssh/gitdeploy/github-Bit-Wasp-bitcoin-p2p-php
Is this ok [y/n]: y
You're using Github! You can paste the key in here: https://github.com/Bit-Wasp/bitcoin-p2p-php/settings/keys
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHfgRkFAO6Du+Drrl+viCa3PxZ51N3+SMxRj2kJ6AhN6XJifXTx39rJpbUGHpyKZQvyPC1/QQNtgShktOw0JPyw= user@dev
Saved key to disk