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_hostsconfig id_dsa.pub
We need to look for id_dsa a pair or id_rsa named file, one with the .pub extension. The .pub file is your public key and the other is the private key. If you cannot find such a file (or there is no .ssh directory at all), you can create them by running the ssh-keygen program. In the LINUX/MAC system, ssh-keygen provided with the SSH package; on Windows, the program is included in the Msysgit package.
$Ssh-keygenGenerating 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-keygenyou 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/BWDSUGPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XAt3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/EnmZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbxNrRFi9wrf+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 the SSH public key