简体   繁体   English

如何在 git 中创建 SSH 密钥

[英]How to Create SSH Key in git

I using the following command to create SSH key in git我使用以下命令在 git 中创建 SSH 密钥

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

on git bash, but when I enter this command on bash it is displaying another command list and not generate SSH Key.在 git bash 上,但是当我在 bash 上输入此命令时,它正在显示另一个命令列表并且不生成 Z765250AZKey.B6C7AC809AC Then how can I generate Key?那么如何生成密钥呢?

Create your ssh key using ssh-keygen -o -t rsa -b 4096 -C "email@example.com"使用ssh-keygen -o -t rsa -b 4096 -C "email@example.com"创建您的 ssh 密钥

After list file in folder ~./ssh and see if your key exist.在文件夹 ~./ssh 中列出文件后,查看您的密钥是否存在。 Use:利用:

ls ~/.ssh/

To Generate ssh:要生成 ssh:

Step 1:步骤1:

ssh-keygen -t rsa -b 4096 -C "example@gmail.com"

Replace it with Your Mail id将其替换为您的邮件 ID

Enter passphrase if you want you can leave this blank如果需要,请输入密码,您可以将其留空

Step 2:第2步:

eval $(ssh-agent -s)

You will get Agent pid (Don't Need to copy it)您将获得代理 pid(不需要复制它)

Step 3:第 3 步:

ssh-add ~/.ssh/id_rsa

Step 4:第4步:

cat < ~/.ssh/id_rsa.pub

Copy Down the Displayed key including your mail id复制显示的密钥,包括您的邮件 ID

Then Goto Github > Settings > SSH And GPG keys > Click New RSA(Green Button) > Give a random title to the key and paste down the key below Tap Add SSH Key.然后转到 Github > 设置 > SSH 和 GPG 密钥 > 单击新建 RSA(绿色按钮) > 为密钥指定一个随机标题,然后将密钥粘贴到点击添加 SSH 密钥下方。

ssh-keygen -t ed25519 -C "your_github_email_address" ssh-keygen -t ed25519 -C "your_github_email_address"

dont write any passphrase, so enter不要写任何密码,所以输入

Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): enter
Enter same passphrase again: enter

pbcopy < ~/.ssh/id_ed25519.pub
cd ~/.ssh
cat id_ed25519.pub 

and copy the content to github并将内容复制到github

ssh-..e9 AAA...+T5 abc@gmail.com

https://medium.com/codex/clone-github-private-repository-using-ssh-on-mac-acc9110d1cfe https://medium.com/codex/clone-github-private-repository-using-ssh-on-mac-acc9110d1cfe

Using SSH (Secure Shell) instead of https seems the Secure & Fastest method.使用 SSH(安全外壳)而不是 https 似乎是安全和最快的方法。 Just providing few links and tips here to make things a bit easy.只需在此处提供一些链接和提示,以使事情变得容易一些。 You can check this step-by-step guide .您可以查看此分步指南 provided by docs,github to "Check existing SSH keys, Generate, Add a new SSH key to your GitHub account. and more."由文档提供,github 到“检查现有的 SSH 密钥,生成,将新的 SSH 密钥添加到您的 ZD3B7C913CBEFDECF8 和 2”。

Tip #1: During the process you need to confirm SSH key fingerprints to validate the connection.提示 #1:在此过程中,您需要确认 SSH 密钥指纹以验证连接。 Compare the key of the algorithm you chose respectively (RSA, ECDSA, or Ed25519) and confirm it.分别比较您选择的算法的密钥(RSA、ECDSA 或 Ed25519)并确认。 Check this link to compare the key: GitHub's public key fingerprints !检查此链接以比较密钥: GitHub 的公钥指纹

Tip #2: If you don't want to type passphrase every time you push, just press enter when it prompts to choose passphrase.提示#2:如果您不想每次推送时都输入密码,只需在提示选择密码时按回车即可。

CAUTION: Other methods using https $ git config credential.helper store etc., even with using 'timeout' might seem faster but are 100% unencrypted and hence not secure.注意:使用 https $ git 配置 credential.helper 存储等的其他方法,即使使用“超时”可能看起来更快,但 100% 未加密,因此不安全。 However, you can encrypt that config file and just decrypt it before use, but there is still a chance we might forget to encrypt it again after use.但是,您可以加密该配置文件并在使用前对其进行解密,但我们仍有可能在使用后忘记再次加密它。 You can use it at your discretion.您可以自行决定使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM