Skip to content

Instantly share code, notes, and snippets.

@milosjanda
Last active July 26, 2020 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milosjanda/a86ebc039293f22fabe723024ec42b46 to your computer and use it in GitHub Desktop.
Save milosjanda/a86ebc039293f22fabe723024ec42b46 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Switching two different SSH identities
# Solve setting of remote url in every repository like https://docs.gitlab.com/ee/ssh/#multiple-accounts-on-a-single-gitlab-instance
#
# 1. Create directory structure:
# ~/.ssh-work
# ├── home
# │ ├── .home # important!
# │ ├── config
# │ ├── id_rsa
# │ ├── known_hosts
# ├── work
# │ ├── .work # important!
# │ ├── config
# │ ├── id_rsa
# │ ├── known_hosts
#
# 2. Edit this scipt
# - set git user email, username, etc.
#
#
# This script create symlink to one of these directory
#
if [[ -f ~/.ssh/.work ]]; then
echo "swith to HOME"
# mv ~/.ssh/id_rsa ~/.ssh/work; mv ~/.ssh/home ~/.ssh/id_rsa
rm ~/.ssh 2> /dev/null
ln -s ~/.ssh-work/home ~/.ssh
git config --global user.email "my.name@gmail.com"
else
echo "swith to WORK"
# mv ~/.ssh/id_rsa ~/.ssh/home; mv ~/.ssh/work ~/.ssh/id_rsa
rm ~/.ssh 2> /dev/null
ln -s ~/.ssh-work/work ~/.ssh
git config --global user.email "my.name@company.eu"
fi
# Delete all identities from ssh-agent
ssh-add -D
# Add new identity to ssh-agent
ssh-add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment