Talk about Git's ssh key

Source: Internet
Author: User
Tags using git

The role of SSH key

When we use SSH to log in to the server, it is common to log in using the username/password method.
You can also use SSH key to implement password-free login, which is generally used in this way by the GIT server more.

Generate SSH Key
"your name"

The default is to generate id_rsa,id_rsa.pub two files in the local ~/.ssh directory,
Id_rsa is the private key, and Id_rsa.pub is the public key.

Using SSH key
    • SSH key mode login to remote server
      We need to copy the id_rsa.pub to the ~/.ssh of the remote server,
      and renamed Authorized_keys so that we can use key to log in
for‘~/.ssh/id_rsa‘:

This allows us to enter the password for Shh key to log in.

    • SSH key mode using git clone code
      If we're using github/gitcafe, we just need to copy the contents of the Id_rsa.pub,
      Add it to GitHub's setting, and we'll be able to use the SSH mode clone code.
//请修改为你自己的git地址git clone [email protected]:chenyangcun/mydouban.git

Multiple sites using different SSH keys

The default SSH login is using the Id_rsa file, we can also specify other files;
First we generate a different key:

"user1"-f"user2"-f user2

We generate user1,user2 two different SSH keys, and then we create a config file under. SSH,
Input:

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

This accesses company.com using User1, and accessing github.com uses User2

Use different SSH keys for the same site

We sometimes need to use different SSH keys at the same site, such as using the Gitcafe pages service,
You want to create two sites, but the Gitcafe does not allow different users to use the same SSH key.
We make the appropriate changes in the config file.

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 the GIT reference

#site1$ $ git remote add origin git@gitcafe-site1:user1/user1.git#site2$ $ 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 gitcafe-site1 in such a way
Deploy
Type:git
Repo: [Email protected]:user1/user1.git

#

The source of this article: http://www.aswifter.com/2015/06/18/git-ssh-key/
Reprint please indicate the source of this article at the beginning.

Welcome to my public number, share swift development, Android development and Internet content
Number: App developer

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Talk about Git's ssh key

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.