[转载]git push 次次都需要输入用户名和密码
2015-10-21 21:14
375 查看
git push 每次都需要输入用户名和密码
解决方案:
每次都需要输入用户名和密码是因为你采用的是 https 方式提交代码, 如果采用的是 ssh 方式只需要在版本库中添加用户的 sha 的key就可以实现提交时无需输入用户名和密码。
详细步骤:
步骤1:
如果你的版本库已经用https 方式创建好了,那么就需要先删除原来的提交方式。在终端执行以下指令:
git remote rm origin
git remote add origin git@github.com:(用户名)/版本库名
然后从远程库连接时 git clone ssh地址 不是https地址就可以了。
这里我提供一下我的具体例子:
https: https://github.com/用户名/GitTest.git
ssh: git@github.com:用户名/GitTest.git
我是怎么知道的呢?如果你在创建版本库时选择不创建README.md,系统会提示你创建:
https:
…or create a new repository on the command line
echo # GitTest >> README.md
git init
git add README.md
git commit -m “first commit”
git remote add origin https://github.com/Sugerming/GitTest.git
git push -u origin master
…or push an existing repository from the command line
git remote add origin https://github.com/Sugerming/GitTest.git
git push -u origin master
ssh:
…or create a new repository on the command line
echo # GitTest >> README.md
git init
git add README.md
git commit -m “first commit”
git remote add origin git@github.com:Sugerming/GitTest.git
git push -u origin master
…or push an existing repository from the command line
git remote add origin git@github.com:Sugerming/GitTest.git
git push -u origin master
步骤2:
然后这个时候你使用下面指令提交代码:
git push -u origin master
系统会提示:
The authenticity of host ‘github.com (192.30.252.131)’ can’t be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘github.com,192.30.252.131’ (RSA) to the list of known h osts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
说明你权限不够。所以这时你需要在本地创建自己的RSA的key。如下:
ssh-keygen -t rsa -C “用户名”
然后系统会问你保存路径等东西,我直接enter跳过了。
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/AlexYi/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
然后系统会生成一些东西:
Your identification has been saved in /c/Users/AlexYi/.ssh/id_rsa.
Your public key has been saved in /c/Users/AlexYi/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:rxfK05d7oZWpDvQ5dRQM0Na7…
The key’s randomart image is:
+—[RSA 2048]—-+
| .o.+. |
| o o.|
| . o|
| o |
…
最主要的是告诉你,你的可以在:
Your public key has been saved in /c/Users/AlexYi/.ssh/id_rsa.pub
找到这个文件,然后用记事本打开,就可以看到自己的key:
ssh-rsa AAAAB3NzaC1yc2EAAAADA…
步骤3:
然后将生成的rsa 的key添加到版本库中即可,方法:
打开自己的版本库,点击右边的 Settings 进入配置页。
然后点击左边导航栏的: Deploy keys 进入添加key页面
然后点击: Add deploy keys ,将自己的内容输入进去就可以了。
这样就完成了。
最后继续提交更改的代码,使用:
git push -u origin master
可以提交成功。
补充:
如果要使用 git push简短提交代码:
git push
需要配置 :
git config –global push.default simple
或者:
git config –global push.default matching
区别在于,前者只提交你当前所在的分支,而后者会提交本地左右的分支。具体的自己去查一下就明白了
解决方案:
每次都需要输入用户名和密码是因为你采用的是 https 方式提交代码, 如果采用的是 ssh 方式只需要在版本库中添加用户的 sha 的key就可以实现提交时无需输入用户名和密码。
详细步骤:
步骤1:
如果你的版本库已经用https 方式创建好了,那么就需要先删除原来的提交方式。在终端执行以下指令:
git remote rm origin
git remote add origin git@github.com:(用户名)/版本库名
然后从远程库连接时 git clone ssh地址 不是https地址就可以了。
这里我提供一下我的具体例子:
https: https://github.com/用户名/GitTest.git
ssh: git@github.com:用户名/GitTest.git
我是怎么知道的呢?如果你在创建版本库时选择不创建README.md,系统会提示你创建:
https:
…or create a new repository on the command line
echo # GitTest >> README.md
git init
git add README.md
git commit -m “first commit”
git remote add origin https://github.com/Sugerming/GitTest.git
git push -u origin master
…or push an existing repository from the command line
git remote add origin https://github.com/Sugerming/GitTest.git
git push -u origin master
ssh:
…or create a new repository on the command line
echo # GitTest >> README.md
git init
git add README.md
git commit -m “first commit”
git remote add origin git@github.com:Sugerming/GitTest.git
git push -u origin master
…or push an existing repository from the command line
git remote add origin git@github.com:Sugerming/GitTest.git
git push -u origin master
步骤2:
然后这个时候你使用下面指令提交代码:
git push -u origin master
系统会提示:
The authenticity of host ‘github.com (192.30.252.131)’ can’t be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘github.com,192.30.252.131’ (RSA) to the list of known h osts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
说明你权限不够。所以这时你需要在本地创建自己的RSA的key。如下:
ssh-keygen -t rsa -C “用户名”
然后系统会问你保存路径等东西,我直接enter跳过了。
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/AlexYi/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
然后系统会生成一些东西:
Your identification has been saved in /c/Users/AlexYi/.ssh/id_rsa.
Your public key has been saved in /c/Users/AlexYi/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:rxfK05d7oZWpDvQ5dRQM0Na7…
The key’s randomart image is:
+—[RSA 2048]—-+
| .o.+. |
| o o.|
| . o|
| o |
…
最主要的是告诉你,你的可以在:
Your public key has been saved in /c/Users/AlexYi/.ssh/id_rsa.pub
找到这个文件,然后用记事本打开,就可以看到自己的key:
ssh-rsa AAAAB3NzaC1yc2EAAAADA…
步骤3:
然后将生成的rsa 的key添加到版本库中即可,方法:
打开自己的版本库,点击右边的 Settings 进入配置页。
然后点击左边导航栏的: Deploy keys 进入添加key页面
然后点击: Add deploy keys ,将自己的内容输入进去就可以了。
这样就完成了。
最后继续提交更改的代码,使用:
git push -u origin master
可以提交成功。
补充:
如果要使用 git push简短提交代码:
git push
需要配置 :
git config –global push.default simple
或者:
git config –global push.default matching
区别在于,前者只提交你当前所在的分支,而后者会提交本地左右的分支。具体的自己去查一下就明白了
相关文章推荐
- 关于ion-view的生命周期及相关事件
- IIS7/IIS7.5中目录执行权限的设置方法
- LeetCode Remove Linked List Elements 链表
- RAII惯用法:C++资源管理的利器
- Linux 操作系统配置——总体架构目录
- 删除链表中(不带头结点)值为value的结点,返回删除的个数
- 硬盘安装Ubuntu12.04
- 修改文件后浏览器自动刷新解决方案
- 8888888888888888
- java 多线程(1) 多线程死锁与同步超时的实现
- 666666666
- 通过TrackPopupMenu函数弹出菜单
- iOS开发之 MVVM的架构设计与团队协作的重要性
- 学生信息是:姓名,学号,性别,年龄,用一个链表,把这些信息连在一起,给出一个age, 在些链表中删除学生年龄等于age的学生信息。
- 通过TrackPopupMenu函数弹出菜单
- 软件自动化测试工具介绍
- 细说.NET 中的多线程 (一 概念)
- Light OJ 1013 - Love Calculator(LCS+ 计方案数)
- Hibernate的generator属性
- c++多线程编程