GitHub: Multiple account setup

后端 未结 4 1179
野性不改
野性不改 2020-12-08 17:53

I am trying since more than 3 hours to setting up multiple account for github and litteraly tired. I have tried out almost all possible way describe here, github and article

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 18:17

    Here is a script to Automate the addition of two GitLab Accounts to your setup.

    setup-gitlab.sh

    #!/bin/bash
    
    # VERIFIED FOR FEDORA 27 MATE (Likely to work in others distros)
    # Multi Account SSH for GitLab/OpenSSH Setup.
    ROOT=root
    if (( whoami == $ROOT ))
        then 
        echo "Run as standard user"
    elif [[ -z $1 || -z $2 ]]
        then
        echo "command usage: setup-gitlab.bash workemail@domain.com homeemail@domain.com"
    elif [[ ! $1 =~ .*@.*\..* ]]
        echo "Work email is not in the correct format. Must match regex .*@.*\..*"
    elif [[ ! $2 =~ .*@.*\..* ]]
        echo "Home email is not in the correct format. Must match regex .*@.*\..*"
    else
        HOMEEMAIL=$1
        WORKEMAIL=$2
        USRNAME=`whomai`
    
    # /home//.ssh/
    # ├── config
    # ├── home-gitlab-key
    # ├── home-gitlab-key.pub
    # ├── known_hosts
    # ├── work-gitlab-key
    # └── work-gitlab-key.pub
    
    #Executed to match the above directory.
        ssh-keygen -t rsa -C "$WORKEMAIL" -b 4096 -f work-gitlab -N ""
        ssh-keygen -t rsa -C "$HOMEEMAIL" -b 4096 -f home-gitlab -N ""
    
    # Agent Configuration Setup (.ssh/config)
        cat >> ~/.ssh/config <> ~/.bashrc <<'EOF'
    eval "$(ssh-agent -s)"
    for i in `ls ~/.ssh/*.pub` ; do ssh-add ${i::-4} ; done
    EOF
    
        . .bashrc
    
    fi
    

    After running the script you will need to copy the contents of the two public keys created to each GitLab account respectively.

    Another note, when using git clone git@gitlab.com:/.git your should replace gitlab.com as follows.

    git clone git@gitlab-home:/.git
    

    and

    git clone git@gitlab-work:/.git
    

    respectively.

提交回复
热议问题