个人工具

“UbuntuHelp:GPGsigningforSSHHowTo”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第2行: 第2行:
 
{{Languages|UbuntuHelp:GPGsigningforSSHHowTo}}
 
{{Languages|UbuntuHelp:GPGsigningforSSHHowTo}}
 
=== Intro ===
 
=== Intro ===
 
 
Often to access a remote server by SSH the administrator of the server will ask for your public ssh_dsa key so that
 
Often to access a remote server by SSH the administrator of the server will ask for your public ssh_dsa key so that
 
he knows it is really your computer that is trying to access his server, and not some hacker. In order to ensure security the administrator will often ask you to first sign the ssh_dsa key using gpg so that
 
he knows it is really your computer that is trying to access his server, and not some hacker. In order to ensure security the administrator will often ask you to first sign the ssh_dsa key using gpg so that
 
he knows the ssh_dsa key comes from you, and that it has not been intercepted by... yup, a hacker.
 
he knows the ssh_dsa key comes from you, and that it has not been intercepted by... yup, a hacker.
 
 
This guide will show you how to generate your ssh and gpg keys and then
 
This guide will show you how to generate your ssh and gpg keys and then
 
how to use them to perform a secure transaction between two partys.
 
how to use them to perform a secure transaction between two partys.
 
This guide should work on any Gnu/Linux operating system.  
 
This guide should work on any Gnu/Linux operating system.  
 
This guide assumes you have already installed <code><nowiki>open-ssh</nowiki></code> and <code><nowiki>gnupg</nowiki></code>.
 
This guide assumes you have already installed <code><nowiki>open-ssh</nowiki></code> and <code><nowiki>gnupg</nowiki></code>.
 
 
=== Generate the SSH DSA keys ===
 
=== Generate the SSH DSA keys ===
 
 
'''Run all commands as a regular user.'''
 
'''Run all commands as a regular user.'''
 
<pre><nowiki>
 
<pre><nowiki>
第20行: 第16行:
 
This will create your public and private ssh-dsa keys
 
This will create your public and private ssh-dsa keys
 
the public key that the administraitor needs should be locaed here: ~/.ssh/id_dsa.pub
 
the public key that the administraitor needs should be locaed here: ~/.ssh/id_dsa.pub
 
 
=== Generate the GPG keys ===
 
=== Generate the GPG keys ===
 
 
I have generated a new key, and posted the output.
 
I have generated a new key, and posted the output.
 
<pre><nowiki>
 
<pre><nowiki>
第30行: 第24行:
 
This is free software, and you are welcome to redistribute it
 
This is free software, and you are welcome to redistribute it
 
under certain conditions. See the file COPYING for details.
 
under certain conditions. See the file COPYING for details.
 
 
gpg: keyring `/home/alex/.gnupg/secring.gpg' created
 
gpg: keyring `/home/alex/.gnupg/secring.gpg' created
 
Please select what kind of key you want:
 
Please select what kind of key you want:
 
 
#->  (1) DSA and ElGamal (default)
 
#->  (1) DSA and ElGamal (default)
 
(2) DSA (sign only)
 
(2) DSA (sign only)
第44行: 第36行:
 
highest suggested keysize is 2048 bits
 
highest suggested keysize is 2048 bits
 
What keysize do you want? (1024)
 
What keysize do you want? (1024)
 
 
#->Requested keysize is 1024 bits
 
#->Requested keysize is 1024 bits
 
Please specify how long the key should be valid.
 
Please specify how long the key should be valid.
第52行: 第43行:
 
<n>m = key expires in n months
 
<n>m = key expires in n months
 
<n>y = key expires in n years
 
<n>y = key expires in n years
 
 
#->Key is valid for? (0)
 
#->Key is valid for? (0)
 
Key does not expire at all
 
Key does not expire at all
 
Is this correct (y/n)? y
 
Is this correct (y/n)? y
 
 
You need a User-ID to identify your key; the software constructs the user id
 
You need a User-ID to identify your key; the software constructs the user id
 
from Real Name, Comment and Email Address in this form:
 
from Real Name, Comment and Email Address in this form:
 
"Heinrich Heine (Der Dichter) <[email protected]>"
 
"Heinrich Heine (Der Dichter) <[email protected]>"
 
 
Real name: mr bo jangles
 
Real name: mr bo jangles
 
Email address: [email protected]
 
Email address: [email protected]
第66行: 第54行:
 
You selected this USER-ID:
 
You selected this USER-ID:
 
"mr bo jangles (comment) <[email protected]>"
 
"mr bo jangles (comment) <[email protected]>"
 
 
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
 
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
 
You need a Passphrase to protect your secret key.
 
You need a Passphrase to protect your secret key.
 
 
#-> passphrase:
 
#-> passphrase:
 
 
We need to generate a lot of random bytes. It is a good idea to perform
 
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
 
some other action (type on the keyboard, move the mouse, utilize the
第84行: 第69行:
 
public and secret key created and signed.
 
public and secret key created and signed.
 
key marked as ultimately trusted.
 
key marked as ultimately trusted.
 
 
pub  1024D/5F6D1662 2005-03-26 mr bo jangles (comment) <[email protected]>
 
pub  1024D/5F6D1662 2005-03-26 mr bo jangles (comment) <[email protected]>
 
Key fingerprint = D1BC 6822 0ACB 0025 8902  6DE7 87EA 4324 5F6D 1662
 
Key fingerprint = D1BC 6822 0ACB 0025 8902  6DE7 87EA 4324 5F6D 1662
 
sub  1024g/0572A97F 2005-03-26
 
sub  1024g/0572A97F 2005-03-26
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Your '''public''' and '''private''' GPG keys should now be located in your ~/.gnupg directory.
 
Your '''public''' and '''private''' GPG keys should now be located in your ~/.gnupg directory.
 
 
Put your '''private''' key on a cd-rom or a floppy or somewhere very safe, but do not lose it or else you will be unable  
 
Put your '''private''' key on a cd-rom or a floppy or somewhere very safe, but do not lose it or else you will be unable  
 
to sign any documents. Never ever give it to '''''anyone''''' under any circumstance. If you have given anyone your private key then you must revoke the key immediately and generate a new set.
 
to sign any documents. Never ever give it to '''''anyone''''' under any circumstance. If you have given anyone your private key then you must revoke the key immediately and generate a new set.
 
 
=== Exchange Public Keys ===
 
=== Exchange Public Keys ===
 
 
It is good practice to put your '''public''' GPG key on a public key server where others can access it easily. [http://biglumber.com Biglumber.com] is a public key server. In order to put your public key on biglumber you will need to go though a verification process with them first.
 
It is good practice to put your '''public''' GPG key on a public key server where others can access it easily. [http://biglumber.com Biglumber.com] is a public key server. In order to put your public key on biglumber you will need to go though a verification process with them first.
 
 
Go to [http://biglumber.com biglumber.com] and put your public key on their server. '''*'''
 
Go to [http://biglumber.com biglumber.com] and put your public key on their server. '''*'''
 
 
While you are at biglumber you will need to find the public key of the Administrator to who you are planning to send your digitally signed and encrypted message. Once you have done that, you must then import the Administrators public key into your keyring.
 
While you are at biglumber you will need to find the public key of the Administrator to who you are planning to send your digitally signed and encrypted message. Once you have done that, you must then import the Administrators public key into your keyring.
 
 
<pre><nowiki>
 
<pre><nowiki>
 
# gpg --import Administrator.pub
 
# gpg --import Administrator.pub
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Now get the Administrators key ID, and your key ID as well:
 
Now get the Administrators key ID, and your key ID as well:
 
<pre><nowiki>
 
<pre><nowiki>
第113行: 第89行:
 
pub  1024D/XYZXYZXY 2005-03-26 Your_Email_Address <[email protected]>
 
pub  1024D/XYZXYZXY 2005-03-26 Your_Email_Address <[email protected]>
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Aministrator ID: ABCABCAB
 
Aministrator ID: ABCABCAB
 
 
Your ID: XYZXYZXY
 
Your ID: XYZXYZXY
 
 
=== Make a Secure Transaction ===
 
=== Make a Secure Transaction ===
 
 
GPG will use your secret key (~/.gnupg/secring.gpg) to sign and
 
GPG will use your secret key (~/.gnupg/secring.gpg) to sign and
 
encrypt your public ssh key (~/.ssh/id_dsa.pub).  
 
encrypt your public ssh key (~/.ssh/id_dsa.pub).  
 
 
Only the Administrator will be able to  unencrypt the file because you are also using '''his''' public key to encrypt it.
 
Only the Administrator will be able to  unencrypt the file because you are also using '''his''' public key to encrypt it.
 
 
In turn, he will only be able to decrypt it if he has '''your''' public key on his key ring.
 
In turn, he will only be able to decrypt it if he has '''your''' public key on his key ring.
 
 
Sign the key:
 
Sign the key:
 
<pre><nowiki>
 
<pre><nowiki>
 
# gpg -u XYZXYZXY -r ABCABCAB --armor --sign --encrypt ~/.ssh/id_dsa.pub
 
# gpg -u XYZXYZXY -r ABCABCAB --armor --sign --encrypt ~/.ssh/id_dsa.pub
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Send the result (id_dsa.pub.gpg) to the Administrator along with a link to
 
Send the result (id_dsa.pub.gpg) to the Administrator along with a link to
 
where you keep your public key on [http://biglumber.com Biglumber]. He will verify the your information and then allow you to access his system by ssh.
 
where you keep your public key on [http://biglumber.com Biglumber]. He will verify the your information and then allow you to access his system by ssh.
 
 
'''*''' In an ideal world you are only supposed to exchange public keys '''directly and in
 
'''*''' In an ideal world you are only supposed to exchange public keys '''directly and in
 
person''', this way you know 100% that the public key truely belongs to the
 
person''', this way you know 100% that the public key truely belongs to the

2007年11月30日 (五) 17:29的版本

Intro

Often to access a remote server by SSH the administrator of the server will ask for your public ssh_dsa key so that he knows it is really your computer that is trying to access his server, and not some hacker. In order to ensure security the administrator will often ask you to first sign the ssh_dsa key using gpg so that he knows the ssh_dsa key comes from you, and that it has not been intercepted by... yup, a hacker. This guide will show you how to generate your ssh and gpg keys and then how to use them to perform a secure transaction between two partys. This guide should work on any Gnu/Linux operating system. This guide assumes you have already installed open-ssh and gnupg.

Generate the SSH DSA keys

Run all commands as a regular user.

# ssh-keygen 

This will create your public and private ssh-dsa keys the public key that the administraitor needs should be locaed here: ~/.ssh/id_dsa.pub

Generate the GPG keys

I have generated a new key, and posted the output.

# gpg --gen-key
gpg (GnuPG) 1.2.5; Copyright (C) 2004 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.
gpg: keyring `/home/alex/.gnupg/secring.gpg' created
Please select what kind of key you want:
#->  (1) DSA and ElGamal (default)
(2) DSA (sign only)
(4) RSA (sign only)
Your selection? 1
DSA keypair will have 1024 bits.
About to generate a new ELG-E keypair.
minimum keysize is  768 bits
default keysize is 1024 bits
highest suggested keysize is 2048 bits
What keysize do you want? (1024)
#->Requested keysize is 1024 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)? y
You need a User-ID to identify your key; the software constructs the user id
from Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <[email protected]>"
Real name: mr bo jangles
Email address: [email protected]
Comment: comment
You selected this USER-ID:
"mr bo jangles (comment) <[email protected]>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
#-> passphrase:
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.
+++++.+++++++++++++++.+++++++++++++++.+++++.++++++++
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.
+++++++++++++++++++++++++.++++++++++..+++++++++++++
public and secret key created and signed.
key marked as ultimately trusted.
pub  1024D/5F6D1662 2005-03-26 mr bo jangles (comment) <[email protected]>
Key fingerprint = D1BC 6822 0ACB 0025 8902  6DE7 87EA 4324 5F6D 1662
sub  1024g/0572A97F 2005-03-26

Your public and private GPG keys should now be located in your ~/.gnupg directory. Put your private key on a cd-rom or a floppy or somewhere very safe, but do not lose it or else you will be unable to sign any documents. Never ever give it to anyone under any circumstance. If you have given anyone your private key then you must revoke the key immediately and generate a new set.

Exchange Public Keys

It is good practice to put your public GPG key on a public key server where others can access it easily. Biglumber.com is a public key server. In order to put your public key on biglumber you will need to go though a verification process with them first. Go to biglumber.com and put your public key on their server. * While you are at biglumber you will need to find the public key of the Administrator to who you are planning to send your digitally signed and encrypted message. Once you have done that, you must then import the Administrators public key into your keyring.

# gpg --import Administrator.pub

Now get the Administrators key ID, and your key ID as well:

# gpg --list-keys
pub  1024D/ABCABCAB 2005-03-26 Administrator_Email <[email protected]>
pub  1024D/XYZXYZXY 2005-03-26 Your_Email_Address <[email protected]>

Aministrator ID: ABCABCAB Your ID: XYZXYZXY

Make a Secure Transaction

GPG will use your secret key (~/.gnupg/secring.gpg) to sign and encrypt your public ssh key (~/.ssh/id_dsa.pub). Only the Administrator will be able to unencrypt the file because you are also using his public key to encrypt it. In turn, he will only be able to decrypt it if he has your public key on his key ring. Sign the key:

# gpg -u XYZXYZXY -r ABCABCAB --armor --sign --encrypt ~/.ssh/id_dsa.pub

Send the result (id_dsa.pub.gpg) to the Administrator along with a link to where you keep your public key on Biglumber. He will verify the your information and then allow you to access his system by ssh. * In an ideal world you are only supposed to exchange public keys directly and in person, this way you know 100% that the public key truely belongs to the correct person.