Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Generate new SSH key
- `$ ssh-keygen -t rsa -C "your_email@email.com"`
- for example, created key for 2 accounts
- ```
- ~/.ssh/id_rsa_user1
- ~/.ssh/id_rsa_user2
- ```
- ## Add SSH keys to ssh-agent
- ```
- $ ssh-add -K ~/.ssh/id_rsa_user1
- $ ssh-add -K ~/.ssh/id_rsa_user2
- ```
- you also need to modify `.ssh/config`
- ```
- #user1 account
- Host github.com-user1
- HostName github.com
- User git
- IdentityFile ~/.ssh/id_rsa_user1
- #user2 account
- Host github.com-user2
- HostName github.com
- User git
- IdentityFile ~/.ssh/id_rsa_user2
- ```
- ## Add SSH key to github account
- copy key to your clipboard then paste it into your github setting
- `$ pbcopy < ~/.ssh/id_rsa_{user}.pub`
- ## Usage
- **setting global git user**
- ```
- git config --global user.email "global_email@email.com"
- git config --global user.name "global-name"
- ```
- **setting local git user**
- ```
- git config user.email "local_email@email.com"
- git config user.name "local-name"
- ```
- then, you also have to delete all SSH keys and add a needed key because global key always overide the local one
- ```
- # delete all keys before
- $ ssh-add -D
- # add needed key
- $ ssh-add ~/.ssh/id_rsa_{user}
- ```
- use `ssh-add -l` to list all added keys
- ## Bonus
- **shell command**
- ```
- guser() {
- G_USER=${1:="global-name"}
- if [ $G_USER = "local-name" ]
- then
- git config user.name "local-name"
- git config user.email "local_email@email.com"
- fi
- ssh-add -D
- ssh-add $HOME/.ssh/id_rsa_$G_USER
- ssh-add -l
- }
- ```
- you can use `guser` for global user and `guser {local-name}` for local user
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement