Last active
July 26, 2020 16:03
-
-
Save milosjanda/a86ebc039293f22fabe723024ec42b46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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