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
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: your should replace gitlab.com as follows.
git clone git@gitlab-home:/.git
and
git clone git@gitlab-work:/.git
respectively.