Http://git-scm.com/book/zh/ch4-3.html
Generate SSH Public key
As mentioned earlier, many Git servers use the SSH public key for authentication. In order to provide the SSH public key to the Git server, if a system user does not already have the key, a copy must be generated beforehand. This process is similar across all operating systems. First, you need to verify that you already have the key. By default, the user's SSH key is stored in its ~/.ssh
directory. By entering the directory and listing the contents, you can quickly confirm that you already have the key:
$
cd
~/.SSH $
lsauthorized_keys2 id_dsa known_hosts
config id_dsa.pub
We need to find a pair with   id_dsa
or   id_rsa
Named file, one with   . pub
  . pub
file is your public key, The other is the private key. If such a file cannot be found (or there is no . SSH
directory), you can run Ssh-keygen
program to create them. In the Linux/mac system, ssh-keygen
with the SSH package, and on Windows, the program is included in the Msysgit in the software package.
$
ssh-keygen Generating public/private RSA key pair.
enter file in which to save the key (/HOME/SCHACON/.SSH/ID_RSA):
created directory '/home/schacon/.ssh '.
enter passphrase (empty for no passphrase):
enter same passphrase again:
your identification has been saved In/home/schacon/.ssh/id_rsa.
your public key has been saved in/home/schacon/.ssh/id_rsa.pub.
the key fingerprint is:
d0:82:24:8e:d7:f1:bb:9b:33:53:96:93:49:da:9b:e3 [email protected]
ssh-keygen
You will first confirm where the key is stored (by default .ssh/id_rsa
), and then it will ask you to enter the key password two times. If you do not want to enter a password when using the key, leave it blank.
Now, users who do this need to send their own public key to any Git server administrator (assuming the server is using the public key-based SSH authentication settings). All they have to do is copy the contents of their .pub
files and send them by email. The public key looks like this:
$
Cat ~/.ssh/id_rsa.pubssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSU
GPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3
Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XA
t3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/En
mZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbx
NrRFi9wrf+M7Q== [email protected]
For a more in-depth tutorial on generating SSH keys in multiple operating systems, see GitHub's SSH key guide https://help.github.com/articles/generating-ssh-keys.
Git on the server-generate SSH public key