为 git 标记生成 GPG 密钥
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12061645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generating a GPG key for git tagging
提问by skytreader
I'm trying to create signed tags in GitHub using the git command line. I generated a GPG key with a (sample) username Full Name (skytreader) <[email protected]>
. Having done that, I try to create a signed tag. However I get the following error:
我正在尝试使用 git 命令行在 GitHub 中创建签名标签。我生成了一个带有(示例)用户名的 GPG 密钥Full Name (skytreader) <[email protected]>
。完成后,我尝试创建一个签名标签。但是我收到以下错误:
gpg: skipped "full <[email protected]>": secret key not available
gpg: signing failed: secret key not available
error: gpg failed to sign the data
error: unable to sign the tag
I figure that I just need to create another key with the indicated username. But then, entering the name "full", gpg
complains that my name should be at least 5 characters long.
我想我只需要使用指定的用户名创建另一个密钥。但是,输入名称“full”后,会gpg
抱怨我的名字至少应有 5 个字符长。
How do I use this key with git?
我如何在 git 中使用这个密钥?
Do I change the username git uses for signing my tags with GPG so that I get a real name at least 5 chars long?
我是否更改了 git 用于使用 GPG 签署标签的用户名,以便获得至少 5 个字符长的真实姓名?
采纳答案by Christopher
The committer name is located in your ~/.gitconfig
file. Change that entry to a real name (which is how you want to be committing, anyway). You can edit the file in your favorite editor, or just issue:
提交者名称位于您的~/.gitconfig
文件中。将该条目更改为真实姓名(无论如何,这是您希望提交的方式)。你可以在你最喜欢的编辑器中编辑文件,或者只是发出:
git config --global user.name "<name>"
回答by mmcorrelo
First you need check if there is a gpg key for your ID.
首先,您需要检查您的 ID 是否有 gpg 密钥。
$ gpg --list-key
If you have should appear something like this:
如果你有应该出现这样的:
- pub 2048R/6AB3587A 2013-05-23
- uid xxx (gpg for xxx)
- sub 2048R/64CB327A 2013-05-23
- 酒吧 2048R/6AB3587A 2013-05-23
- uid xxx(xxx 的 gpg)
- 子 2048R/64CB327A 2013-05-23
If there is no gpg key. You should create
如果没有 gpg 密钥。你应该创建
$ gpg --gen-key
Next you have this output:
接下来你有这个输出:
gpg (GnuPG) 2.0.14; Copyright (C) 2009 Free Software Foundation, Inc. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
- (1) RSA and RSA (default)
- (2) DSA and Elgamal
- (3) DSA (sign only)
- (4) RSA (sign only)
Your selection? RSA keys may be between 1024 and 4096 bits long. What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) yGnuPG needs to construct a user ID to identify your key. Real name: xxx Email address: [email protected] Comment: gpg for xxx You selected this USER-ID: "xxx(gpg for xxx) <[email protected]>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O You need a Passphrase to protect your secret key. can't connect to `/xxx/.gnupg/S.gpg-agent': No such file or directory We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy.
gpg (GnuPG) 2.0.14;版权所有 (C) 2009 Free Software Foundation, Inc。这是免费软件:您可以自由更改和重新分发它。在法律允许的范围内,不提供任何保证。
请选择您想要的密钥类型:
- (1) RSA 和 RSA(默认)
- (2) DSA 和 Elgamal
- (3) DSA(仅签名)
- (4) RSA(仅签名)
你的选择?RSA 密钥的长度可能在 1024 到 4096 位之间。你想要什么键大小?(2048)
请求的密钥大小为 2048 位
请指定密钥的有效期。0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years
密钥对什么有效?(0)
密钥根本不会过期 这
是正确的吗?(y/N) 是GnuPG needs to construct a user ID to identify your key. Real name: xxx Email address: [email protected] Comment: gpg for xxx You selected this USER-ID: "xxx(gpg for xxx) <[email protected]>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O You need a Passphrase to protect your secret key. can't connect to `/xxx/.gnupg/S.gpg-agent': No such file or directory We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy.
回答by user2943160
If you have a key already generated, you can tell git to use that specific key without worrying about matching between your git user ID (name+email) and the GPG key's ID. You should have your git user.email
match one of the emails on your GPG key for your signed tags or commits to be useful to other users, though.
如果您已经生成了一个密钥,您可以告诉 git 使用该特定密钥,而不必担心您的 git 用户 ID(姓名+电子邮件)和 GPG 密钥 ID 之间的匹配。不过,您应该让您的 gituser.email
与您的 GPG 密钥上的一封电子邮件匹配,以获取您的签名标签或承诺对其他用户有用。
To set the key for global use on your computer, set your git global config with:
要在您的计算机上设置全局使用的密钥,请使用以下命令设置您的 git 全局配置:
git config --global user.signingkey 6AB3587A
Or, you can set the user.signingkey
for only the current repository you're in with:
或者,您可以user.signingkey
仅为您所在的当前存储库设置:
git config user.signingkey 6AB3587A