Let's talk about Git's ssh key and gitsshkey.

Source: Internet
Author: User

Let's talk about Git's ssh key and gitsshkey.
Role of the ssh key

When we use ssh to log on to the server, we usually use the user name/password to log on,
You can also use the ssh key for password-free login. This method is usually used by Git servers.

Generate an ssh key
ssh-keygen -t rsa -C "your name"

By default ~ /. The id_rsa and id_rsa.pub files are generated under the ssh directory,
Id_rsa is the private key and id_rsa.pub is the public key.

Use ssh key
  • Log on to the remote server using ssh key
    We need to copy id_rsa.pub to the remote server ~ /. Ssh,
    And rename it authorized_keys, so that we can use the key method to log on.
$ ssh git@your.server.comEnter passphrase for key '~/.ssh/id_rsa':

In this way, we can enter the shh key password to log on.

  • Use git clone code using ssh key
    If we use github/gitcafe, we only need to copy the id_rsa.pub content,
    Add it to setting on github. we can clone the code using ssh.
// Modify your own git address git clone git@github.com: chenyangcun/mydouban. git

Use different ssh keys for multiple sites

By default, the id_rsa file is used for ssh logon. You can specify other files;
First, we generate different keys:

ssh-keygen -t rsa -C "user1" -f user1ssh-keygen -t rsa -C "user2" -f user2

We generate two different ssh keys, user1 and user2. Then we create the config file under. ssh,
Input:

Host company  HostName company.com  User git  IdentityFile ~/.ssh/user1Host github  HostName github.com  User git  IdentityFile ~/.ssh/user2

In this way, user1 is used to access company.com, and user2 is used to access github.com.

Use different ssh keys for the same site

We sometimes need to use different ssh keys on the same site, such as the pages service of gitcafe,
You want to create two sites, but gitcafe does not allow different users to use the same ssh key,
Modify the config file accordingly.

Host gitcafe-site1  HostName gitcafe.com  User git  IdentityFile ~/.ssh/user1Host gitcafe-site2  HostName gitcafe.com  User git  IdentityFile ~/.ssh/user2

Then we change the remote address of git reference.

#site1$ git remote remove origin $ git remote add origin git@gitcafe-site1:user1/user1.git#site2$ git remote remove origin $ git remote add origin git@gitcafe-site2:user2/user2.git

The key is to change gitcafe.com to gitcafe-site1 and gitcafe-site2

If you use hexo, In the config file of hexo, change the remote address of deploy to the form of gitcafe-site1.
Deploy:
Type: git
Repo: GitHub @ gitcafe-site1: user1/user1.git

#

Source: http://www.aswifter.com/2015/06/18/git-ssh-key/
For reprinting, please indicate the source of this article at the beginning.

Welcome to my public account, share Swift development, Android development, and Internet content
No.: APP developer

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.