在Windows 10中使用ssh键设置git权限

If you want to use git in your local PC and it’s a bit hard to “pull” and “push” you can simplify that using adding public ssh key to your GitHub account.

如果要在本地PC上使用git,“拉”和“推”有点困难,则可以通过在GitHub帐户中添加公共ssh密钥来简化此操作。

To start first go to your PC, .ssh folder. It’s in “C:\Users\<Your Profile>\.ssh”

首先,请转到您的PC .ssh文件夹。 在“ C:\ Users \ <您的配置文件> \。ssh”中

“C” may change with your OS installed partition. To see the “.ssh” folder you need to tick view hidden files.

“ C”可能会随操作系统安装的分区而改变。 要查看“ .ssh”文件夹,您需要勾选查看隐藏文件。

If you already have “id_rsa” and “id_rsa.pub” files in the “.ssh” folder skip the next part. However, if you want to create a new SSH key for git do not skip.

如果“ .ssh”文件夹中已经有“ id_rsa”和“ id_rsa.pub”文件,请跳过下一部分。 但是,如果要为git创建新的SSH密钥,请不要跳过。

Generate SSH key

生成SSH密钥

  1. Open Powershell or Command Prompt in the “.ssh” folder.

    在“ .ssh”文件夹中打开Powershell或命令提示符。

2. Use the command ssh-keygen

2.使用命令ssh-keygen

3. It will start generating a new SSH key, the first popup will ask to use default id_rsa file name for the key. If you already have a key or you want to rename your old keypress enter, else enter a new SSH key name.

3.它将开始生成新的SSH密钥,第一个弹出窗口将要求使用默认的id_rsa文件名作为密钥。 如果您已经有一个密钥或要重命名旧的密钥,请按Enter,否则输入新的SSH密钥名称。

Image for post
SSH key name
SSH密钥名称

4. Then comes the critical part. After pressing enter, the next message asked for a passphrase. the passphrase will need for every time you use the new SSH key. If you do not want to enter key every time you pull or push, then add an empty passphrase press enter. However, the passphrase will add an extra security layer for your GitHub repositories. Anyway, it’s better to use any passphrase.

4.接下来是关键部分。 按回车后,下一条消息要求输入密码。 每次您使用新的SSH密钥时,都需要使用密码。 如果您不想在每次拉动或推入时都输入密钥,请添加一个空密码,按Enter键。 但是,密码短语将为您的GitHub存储库添加一个额外的安全层。 无论如何,最好使用任何密码短语。

Image for post
Passphrase
密码短语

5. After pressing enter, you will ask to enter the passphrase again. If you enter one then type that and press enter else press enter without typing anything.

5.按Enter键后,您将要求再次输入密码。 如果输入一个,则键入该内容,然后按Enter键,否则按Enter键而不输入任何内容。

Image for post
Enter passphrase again
再次输入密码

Finally, the SSH key is generated.

最后,将生成SSH密钥。

Image for post
SSH key
SSH密钥

You will notice two new files have been generated. One without any extension and other with “.pub” extension. The file without extension is the private key that you do not need to share. Another file is the public key which you have to share with others you want to connect with. In this case, it is GitHub.

您会注意到已经生成了两个新文件。 一个不带任何扩展名,另一个带“ .pub”扩展名。 不带扩展名的文件是您不需要共享的私钥。 另一个文件是公用密钥,您必须与要连接的其他人共享。 在这种情况下,它是GitHub。

Add SSH key to Github

将SSH密钥添加到Github

Now you have a new key if you went through the last section else you have an old SSH key.

现在,如果您经过上一节的内容,则拥有一个新密钥,否则您将拥有一个旧的SSH密钥。

  1. Enter cat id_rsa.pub or cat <your ssh file name>.pub if you use a different name and copy the file content.

    如果使用其他名称并输入文件内容,请输入cat id_rsa.pub或cat <您的ssh文件名> .pub。
Image for post
Public key
公钥

2. Go to your GitHub account and click your profile image at the to right. then click on Settings -> SSH and GPG keys.

2.转到您的GitHub帐户,然后单击右侧的您的个人资料图像。 然后单击设置-> SSH和GPG密钥。

Image for post
Go to Settings
前往设置
Image for post
Go to SSH keys
转到SSH密钥
Image for post
Click on New SSH key
点击新的SSH密钥

3. Then click on “New SSH Key” button to enter new SSH key

3.然后点击“新建SSH密钥”按钮以输入新的SSH密钥

4. In the form Add title as you want, It will only be used as an identification mechanic for you. Then enter the Copied SSH key at the key area.

4.在“添加标题”表格中,它将仅用作您的标识机制。 然后在密钥区域输入“复制的SSH”密钥。

Image for post
Enter SSH key
输入SSH密钥

Finally, Enter “Add SSH key”.

最后,输入“添加SSH密钥”。

Wow. It’s a lot. Finally, all done. now you can push, pull fetch, rebase, and many more with this Github account without any hassle.

哇。 好多 最后,一切都完成了。 现在,您可以使用此Github帐户进行推送,提取,重新设置等操作,而不会遇到任何麻烦。

翻译自: https://medium.com/@sasitha.iresha/set-git-permission-using-ssh-keys-in-windows-10-fbb6b06e96f0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值