Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a non-default key name (other than id_rsa)

Tags:

git

github

ssh

I have set the Github passwordless login as below.

ssh-keygen -t rsa  -P ''  
cat .ssh/id_rsa.pub  |xclip 

I pasted the public key into ssh and gpg keys on the Github site.

git init  
git config --global user.name "someone"  
git config --global user.email  "[email protected]"  
git config remote.origin.url git+ssh://[email protected]/someone/newstart.git  
ssh -T [email protected]  
git clone  git+ssh://[email protected]/someone/newstart.git   /tmp/newstart

The above works.

Now I want to use a different key name for Github instead of its default name id_rsa.

ssh-keygen -t rsa  -P ''  -f  .ssh/id_rsa.github
cat .ssh/id_rsa.github.pub  |xclip 

I pasted the new pub key into ssh and gpg keys on the Github site.

git init  
git config --global user.name "someone"  
git config --global user.email  "[email protected]"  
git config remote.origin.url git+ssh://[email protected]/someone/newstart.git  
ssh -T [email protected] 

The above does not work.

git clone  git+ssh://[email protected]/someone/newstart.git   /tmp/newstart

The above also does not work.

ssh -i .ssh/id_rsa.github -T [email protected]

The command above can connect to Github successfully, but I can't type the following command to clone the repository.

git clone  -i  .ssh/id_rsa.github  git+ssh://[email protected]/someone/newstart.git   /tmp/newstart

Can't I use a pub key with another name, such as id_rsa.github instead of the default name id_rsa?

like image 833
showkey Avatar asked Jan 01 '17 02:01

showkey


People also ask

Does SSH key have to be named id_rsa?

You can use key with any name. But you should set it explicitly when making ssh connection.

Can I rename id_rsa?

Multiple keys If there is already id_rsa file on the second computer, it is possible to rename the key to something else and then specify the key name when making an SSH connection.

Which key does SSH use by default?

Linux/Mac Instructions: ssh/ directory by default, including your private key, but you may specify a direct location. Never share your private key.


1 Answers

You need to tell SSH to use this key for Github. Put this in ~/.ssh/config:

Host github.com
    IdentityFile ~/.ssh/id_rsa.github
    User git
like image 100
Dan Lowe Avatar answered Sep 22 '22 04:09

Dan Lowe