问题
Is it possible to have multiple public key files? If so, is there someone that can provide an instructional link or a quick how-to? I googled, but can't find what I'm looking for, so now I'm thinking I can't do it?
回答1:
git just uses SSH, so the trick here is to configure SSH into doing what you want.
As it happens, this is trivial by setting up an ssh config file, as described here: http://lookherefirst.wordpress.com/2007/12/17/a-simple-ssh-config-file/
You'll likely want to set up a different "Host" for each public/private key pair you want to use, and therefore, your git repo will have an upstream for each of those. (It doesn't matter that the different "Host" entries resolve to the same "Hostname".)
回答2:
Based on your question assuming you've 1 or more workstations(laptops & PCs) and you want to have multiple public ssh keys. Please follow these steps.
Step 1: Open your command prompt.
Step 2: Check your available ssh keys, first
home@name:~$ $ ls -al ~/.ssh
You'll see some files if you've Example: id_pra.pub id_prab.pub id_rsa
Step 3: Generate a new SSH key with an email as a provider Generate a new SSH key, copy and paste the text below, making sure to substitute in your email address. The default settings are preferred, so when you're prompted to "Enter a file in which to save the key", just press Enter to continue.
home@name:~$ ssh-keygen -t rsa -C "your-email@example.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/you/.ssh/id_rsa):
Now, you'll be asked to enter a passphrase or strong password
Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]
If the password matches you'll see something like this.
Your identification has been saved in /home/you/.ssh/id_rsa.
# Your public key has been saved in /home/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:1f:f5:3d:cb:82:d3:19:a1:7f:f1:58:4d:f2:a1:db your-email@example.com
Now add your new key to the ssh-agent:
home@name:~$ eval "$(ssh-agent -s)"
Agent pid 63675
home@name:~$ ssh-add ~/.ssh/id_rsa
Step 4: Next Add your SSH key to your account(Github/bitbucket)
Run the following commands to copy the key to your clipboard. Keep in mind that your key may also be named id_dsa.pub, id_ecdsa.pub or id_ed25519.pub.
home@name:~$ sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might
need to use another installer (like `yum`)
home@name:~$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
Another way of doing this is open the .ssh directory in your text editor and copy the code from your ssh key file. Example file name id_rsa.pub Now login to your Github and click on account settings, and then SSH keys, then click on Add key button and paste the code and give it a title(may be your pc or laptop name).
Step 5: To make sure everything is working, you'll now try SSHing to GitHub. When you do this, you will be asked to authenticate this action using your password, which was the passphrase you created earlier.
Open your terminal and type this
home@name:~$ ssh -T git@github.com
# Attempts to ssh to GitHub
It's possible that you'll see this error message:
The authenticity of host 'github.com (207.97.227.239)' can't be established.
# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?
Finally you'll see this message if everything is correctly configured.
Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.
You're done!.
回答3:
Of course you can generate multiple key pairs (e.g. for different machines).
Just have a look at the official github help page. You can manage your keys under "Account Settings"
来源:https://stackoverflow.com/questions/5411823/mac-os-x-github-multiple-public-keys