banner
ZDawn

ZDawn

Do one thing at a time and do well.
tg_channel

Configure different keys for SSH to facilitate access to different accounts.

Objective#

Use three keys for three accounts simultaneously.

  • Github-senlief - senlief.github
  • Github-janzbff - janzbff.github
  • Gitlab-moqi - moqi.gitlab

Generate the required three key pairs#

$ ssh-keygen -t ecdsa -f ~/.ssh/senlief.github
$ ssh-keygen -t ecdsa -f ~/.ssh/janzbff.github
$ ssh-keygen -t ecdsa -f ~/.ssh/moqi.gitlab

Add the three public keys to the corresponding websites and accounts#

$ cat ~/.ssh/senlief.github.pub
$ cat ~/.ssh/janzbff.github.pub
$ cat ~/.ssh/moqi.gitlab.pub

Configure the config file#

# Edit the config file or create a new one if it doesn't exist
$ vim ~/.ssh/config

Example configuration#

# senlief.github
Host  senlief.github
	HostName github.com 
	PreferredAuthentications publickey 
	IdentityFile ~/.ssh/senlief.github

# janzbff.github
Host janzbff.github
	HostName github.com 
	PreferredAuthentications publickey 
	IdentityFile ~/.ssh/janzbff.github

# moqi.gitlab
Host moqi.gitlab
	HostName gitlab.com 
	PreferredAuthentications publickey 
	IdentityFile ~/.ssh/moqi.github

Test#

# Use Host instead of Hostname
$ ssh -T git@senlief.github
$ ssh -T git@janzbff.github
$ ssh -T git@moqi.gitlab

Enjoy!#

To clone, simply replace the Hostname in the git address with the Host.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.