生成用于git标记的GPG密钥

时间:2012-08-21 19:23:34

标签: git gnupg

我正在尝试使用git命令行在GitHub中创建签名标签。我使用(样本)用户名Full Name (skytreader) <fullname@gmail.com>生成了一个GPG密钥。完成后,我尝试创建signed tag。但是我收到以下错误:

gpg: skipped "full <fullname@gmail.com>": secret key not available
gpg: signing failed: secret key not available
error: gpg failed to sign the data
error: unable to sign the tag

我认为我只需要用指定的用户名创建另一个密钥。但是,输入名称“full”,gpg会抱怨我的名字至少应该是5个字符。

如何在git中使用此密钥?

我是否更改git用于使用GPG签名我的标签的用户名,以便获得至少5个字符长的真实姓名?

3 个答案:

答案 0 :(得分:38)

首先,您需要检查您的ID是否有gpg密钥。

$ gpg --list-key

如果你有这样的东西:

  
      
  1. pub 2048R / 6AB3587A 2013-05-23
  2.   
  3. uid xxx(gpg for xxx)
  4.   
  5. sub 2048R / 64CB327A 2013-05-23
  6.   

如果没有gpg键。你应该创建

$ gpg --gen-key

接下来你有了这个输出:

  

gpg(GnuPG)2.0.14;版权所有(C)2009 Free Software Foundation,Inc。   这是免费软件:您可以自由更改并重新分发它。   在法律允许的范围内,不作任何担保。

     

请选择您想要的密钥类型:

     
      
  1. (1)RSA和RSA(默认)
  2.   
  3. (2)DSA和Elgamal
  4.   
  5. (3)DSA(仅签名)
  6.   
  7. (4)RSA(仅签名)
  8.         

    您的选择? 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

    GnuPG needs to construct a user ID to identify your key.
    
    Real name: xxx
    Email address: xxx@example.com
    Comment: gpg for xxx
    
    You selected this USER-ID:
        "xxx(gpg for xxx) <xxx@example.com>"
    
    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.
    

答案 1 :(得分:16)

提交者名称位于~/.gitconfig文件中。将该条目更改为真实姓名(无论如何,这是您想要提交的方式)。您可以在您喜欢的编辑器中编辑该文件,或者只发出:

git config --global user.name "<name>"

答案 2 :(得分:8)

如果您已经生成了密钥,您可以告诉git使用该特定密钥,而不必担心您的git用户ID(名称+电子邮件)与GPG密钥的ID之间的匹配。您应该让您的git user.email与您的GPG密钥上的其中一封电子邮件匹配,以便签名标签或提交对其他用户有用。

要设置计算机上全局使用的密钥,请使用以下命令设置git global config:

git config --global user.signingkey 6AB3587A

或者,您可以仅为您当前使用的存储库设置user.signingkey

git config user.signingkey 6AB3587A