ssh-key-config

Generate ssh-Keygen file

The configuration of ssh-key for multi-user

First account:

1
$ ssh-keygen -t rsa -C "first@github.com"

It will ask for ‘keygen’ filename and password you want, please set different filename for accounts.

1
$ ssh-add ~/.ssh/filename1

For another accout, excute the same commands as above

1
2
$ ssh-keygen -t rsa -C "first@github.com"
$ ssh-add ~/.ssh/filename2

If abort fatal ‘Could not open a connection to your authentication agent’

Maybe we could try:

1
$ ssh-agent bash

which means ssh-agent need to start bash.


Setup ‘config’ file

config file is in ~/.ssh

if config does not exit, please use touch or vim to generate a new config file.

1
$ touch config & vim config

The config containing:

1
2
3
4
5
6
7
8
9
10
11
# github for work
Host github.com
HostName github.com # for github
User git
IdentityFile ~/.ssh/first_filename # ssh-keygen generated file

# github for personal
Host personal.github.com
HostName github.com # for github
User git
IdentityFile ~/.ssh/second_filename

After saving config file, please try whether the configurate is right.

Before that, we should copy the documents in first_filename.pub and second_filename.pub into corresponding github account, the documents start with ssh-rsa.

Now, let us test whether the configurate is right.

For first account:

1
$ ssh -T git@github.com

if the output is:

1
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

Which means the configuration is fine.

Now, try the second account:

1
$ ssh -T git@personal.github.com # git@Host in config file

If there’s no mistake, you will get:

1
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

Finally, if you want to configure hexo _config.yaml file to push on github, you could try to revise the _config.yaml:

1
2
3
4
deploy:
type: git
repository: git@personal.github.com:username/username.github.io.git # change githubuser to your own github user name
branch: master