Use git SSH

Source: Internet
Author: User
Tags ssh server
I. Preface

I have been using HTTPS to push the repository. The disadvantage is that I need to enter the account and password each time. If you use SSH, you do not need to enter the password.

Ii. Use
  • Single SSH
    Using GitHub as the remote repository server only requires an SSH.
    Generate SSH:

    ssh-keygen -t rsa -C "[email protected]"  -f ~/.ssh/github_id_rsa

    By using the preceding command~ /. SSH (Windows in C:/users/admininstrator/. Ssh /)Generate two files: github_id_rsa and github_id_rsa.pub. Save the private key and Public Key respectively.

    View the public key:

    cat ~/.ssh/github_id_rsa.pub

    Run the preceding command to view the content of the github_id_rsa.pub file and output the public key,Copy the Public Key

    Open GitHub and add the SSH public key:

    Paste the copied Public Key in the key and enter the title at will.

    Check whether the link is successful:

    ssh -T [email protected]

    Returns a statement containing successfully words, indicating that the link is successful.

    Use SSH push/pull Repository:
    Enter a repository and clone the repository SSH

    Then, use the SSH

    Git remote add GitHub 'ssh just copied'
    In this way, you can use SSH for Push/pull.
  • Multiple SSH
    When multiple git remote servers are used, such as code cloud and GitHub. In this case, you need to manage multiple SSH instances.
    Generate public key

    ssh-keygen -t rsa -C "[email protected]"  -f ~/.ssh/gitee_id_rsassh-keygen -t rsa -C "[email protected]"  -f ~/.ssh/github_id_rsa

    The key here is to save the public key in different files, that is, to distinguish them.
    View Public Key

    cat ~/.ssh/github_id_rsa.pubcat ~/.ssh/gitee_id_rsa.pub

    Add the public key to the remote server (Code cloud, GitHub) (omitted)

    Configure config
    In ~ /. SSH (Windows creates a config file in the C:/users/admininstrator/. Ssh/directory)(Excluding the extension). Add the following content to the file:

    # giteeHost gitee.comHostName gitee.comPreferredAuthentications publickeyIdentityFile ~/.ssh/gitee_id_rsa# githubHost github.comHostName github.comPreferredAuthentications publickeyIdentityFile ~/.ssh/github_id_rsa

    Check whether the connection is successful

    $ ssh -T [email protected]$ ssh -T [email protected]

    At the same time, the know_hosts file is generated in the. Ssh directory to distinguish different SSH
    Use SSH to push and pull (omitted)

Tip: the configuration steps for a single SSH server and multiple SSH servers are not much different. When there are multiple SSH servers, you need to add a config file to differentiate SSH servers.

Use git SSH

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.