Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

force Git to create the ssh-key in the directory directory

I want to push an project to the github homepage. Therefor, I am trying to create ssh-key for the github to manage it but I am facing problem that git creates the ssh-key in the wrong directory /c/Users/user82/.ssh/id_rsa) and not in the project directory /desktop/dogs.

How can I tell Git to create ssh-key in the project directory also /desktop/dogs and not in this directory c/Users/user82?

user82@User MINGW64 ~/desktop/dogs (master)
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/user82/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/user82/.ssh/id_rsa.
Your public key has been saved in /c/Users/user82/.ssh/id_rsa.pub.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

ssh keys are always saved by default in $HOME (which on Windows, is set by git to %USERPROFILE%, which is C:Users<yourLogin>)

ssh will look for those keys in $HOME.

If you want to have keys specific to a GitHub account, you ca:

  • generate ssh keys anywhere you want (or copy them from $HOME to anywhere you want, with any name and name.pub) with ssh-keygen -f
  • reference them in a ssh config file like this one
  • change the remote url to reference the right entry in that ssh config file.

     cd / path/to/your/local/repo
     git remote set-url origin github1:username/myrepo
    

That is with a $HOME/.ssh/config with:

Host github1
  HostName github.com
  User git
  IdentityFile /c/path/to/my/private/key

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...