sty*_*972 0 git authentication command-line github ssh-keys
当我git pull
通过命令行执行操作时,它总是要求我的github用户名和密码.我想告诉它在github中使用ssh密钥,再也不用担心了.你怎么做到这一点?
Jac*_*k M 16
要告诉 Git 使用您生成的密钥,请将以下内容添加到 ssh 配置中(在 Linux 上,通常位于~/.ssh/config
):
Host github.com
User git
IdentityFile ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)
对于 ,IdentityFile
您应该使用由 生成的密钥ssh-keygen
(而不是名称以 结尾的密钥.pub
)。必须User
始终如此git
。
假设您已经习惯ssh-keygen
生成密钥对并将公钥上传到您的github帐户中的适当位置,您应该能够将远程设置为使用该URL git@github.com:username/repo.git
.
git remote set-url origin git@github.com:username/repo.git
Run Code Online (Sandbox Code Playgroud)
如果您没有关心的本地更改,则可以删除本地存储库并再次克隆:
git clone git@github.com:username/repo.git
Run Code Online (Sandbox Code Playgroud)
以下是github关于此设置的说明,您可以根据需要将其用作参考.