Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...