Add multiple git accounts to your Mac

Source: Internet
Author: User

Mac generate multiple accounts start ssh-agent service mode
    1. Generate a public key with multiple names
ssh-keygen -t rsa -C "[email protected]"  # Generating public/private rsa key pair...# 三次回车即可生成 ssh key# 第一次回车修改默认密钥名称 比如: github.com
    1. Start the Ssh-agent service
$ eval "$(ssh-agent -s)"Agent pid 2429
    1. Add the newly added ssh-key to the Ssh-agent service
$ ssh-add ~/.ssh/github.comIdentity added: /Users/andyniu/.ssh/gitee.com (/Users/andyniu/.ssh/gitee.com)

This may be problematic when you close the terminal and may fail

Add Config file config
    1. Create config configuration file
$ touch ~/.ssh/config

Edit Config file

#该文件用于配置私钥对应的服务器#gitHub user([email protected]***.com) Host github.com HostName github.com User git #用户 IdentityFile ~/.ssh/id_rsa_github.com#######################################Add gitLab user([email protected]****.com) Host git.****.com HostName git.****.com User git IdentityFile ~/.ssh/id_rsa_***
    1. Verify
$ ssh -T [email protected]Hi username! You've successfully authenticated, but GitHub does not provide shell access.# 上面是github的成功返回语句,下面是gitlab的成功返回语句。$ ssh -T [email protected]Welcome to GitLab, username!

Add multiple git accounts to your Mac

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.