git生成ssh key 避免每次push都要输入账号密码。


git生成ssh key 避免每次push都要输入账号密码。


核心步骤


第一步、在本地生成id_rsa.pub文件


第二步、将id_rsa.pub文件中的内容添加到github上的Add SSH key页面即可


第三步、[必要]使用ssh地址而非https地址的方式git clone,或者 改变remote远程url为ssh


一种方式就是在git clone的时候使用ssh方式


两个方式的url地址不同,认证方式也不同。使用ssh时保存密钥对以后可以不再输入帐号密码,
而https却不能。

另一种方式就是改变remote远程url,如下:

[plain]   view plain   copy
  1. $ git remote rm origin  
  2. $ git remote add origin [email protected]:cld378632668/utils.git

Windows上的操作方式


第一步:生成public/private rsa key pair

在git的安装目录的bin下,双击bash.exe,在命令行中输入

$ ssh-keygen -t rsa -C [email protected]
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/t-lichen/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): ,通常不设置,按enter跳过即可
Enter same passphrase again: ,通常不设置,按enter跳过即可
Your identification has been saved in /c/Users/t-lichen/.ssh/id_rsa.
Your public key has been saved in /c/Users/t-lichen/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:TXxujQkgphkMOBBnmwehGNMfFSTPWnTuFtJtGeqH328 [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|*+*+ooB.o . |
|+*.+oX = = o |
|o.o.+.= = B . |
| ..o + * + + |
| . S o = . |
| . o o |
| . . |
| .E |
| .. |
+----[SHA256]-----+

根据上面的输出,会在 (/c/Users/t-lichen/.ssh/ 生成 id_rsa id_rsa.pub 两个文件

 
其中输入passphrase(本步骤可以跳过) ,则进行版本控制时,每次与GitHub通信都会要求输入passphrase,以避免某些“失误 ,通常不设置,按enter跳过即可


Linux下


创建用户
git config -- global user.name "你的名字" git config --g lobal user.email " 你的邮箱"


创建秘钥(用来防止每次commit或push都需要密码)
ssh-keygen -t rsa -C "你的邮箱"








猜你喜欢

转载自blog.csdn.net/wzwdcld/article/details/80782561