Git推送需要用户名和密码
我将 Git 存储库从我的 GitHub 帐户克隆到我的 PC。
我想同时使用我的 PC 和笔记本电脑,但使用一个 GitHub 帐户。
当我尝试使用 PC 向 GitHub 推送或拉取时,它需要用户名和密码,但当我使用笔记本电脑时则不需要!
我不想每次与origin
交互时都输入用户名和密码。我在这里缺少什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(30)
一个常见原因是使用默认 (HTTPS) 而不是 SSH 进行克隆。您可以通过以下方式纠正此问题:转到您的存储库,单击“克隆或下载”,然后单击 URL 字段上方的“使用 SSH”按钮并更新原始远程的 URL,如下所示:
您可以检查是否已将远程添加为使用 HTTPS 或 SSH:
这在 GitHub 上有记录:将远程 URL 从 HTTPS 切换到 SSH。
A common cause is cloning using the default (HTTPS) instead of SSH. You can correct this by going to your repository, clicking "Clone or download", then clicking the "Use SSH" button above the URL field and updating the URL of your origin remote like this:
You can check if you have added the remote as HTTPS or SSH using:
This is documented at GitHub: Switching remote URLs from HTTPS to SSH.
使用 Git 存储库永久进行身份验证
运行以下命令以启用 凭证缓存:
您还应该指定缓存过期,
启用凭证缓存后,它将被缓存7200秒(2小时)。 43,200 秒 = 12 小时(每天登录一次)对于某些人来说也可能是一个合理的选择。
正如 SebastianH 评论的那样,也可以使用类似的命令来配置它,而不是针对每个存储库,而是全局配置:
Permanently authenticating with Git repositories
Run the following command to enable credential caching:
You should also specify caching expire,
After enabling credential caching, it will be cached for 7200 seconds (2 hour). 43,200 s = 12 h (login once per day) might also be a reasonable choice for some.
As SebastianH commented, can also use similar commands to configure this not per repository but globally:
我刚刚遇到了同样的问题,我发现的最简单的解决方案是使用 SSH URL 而不是 HTTPS:
而不是这样:
您现在可以使用 SSH 密钥而不是
进行验证用户名
和密码
。I just came across the same problem, and the simplest solution I found was to use SSH URL instead of HTTPS one:
And not this:
You can now validate with just the SSH key instead of the
username
andpassword
.除了更改为 SSH 之外,如果您不介意以明文形式输入密码,还可以继续使用 HTTPS。将其放入您的
~/.netrc
中,它不会询问您的用户名/密码(至少在 Linux 和 Mac 上):添加(请参阅 VonC 的第二条评论):在 Windows 上,文件名为
%HOME%\_netrc
。如果您想加密,另请阅读 VonC 的第一条评论。
另一个补充(请参阅 user137717 的评论),如果您有 Git 1.7.10 或更高版本,则可以使用它。
使用凭证助手在 Git 中缓存 GitHub 密码 :
这也适用于 Linux、Mac 和 Windows。
Apart from changing to SSH you can also keep using HTTPS, if you don't mind to put your password in clear text. Put this in your
~/.netrc
and it won't ask for your username/password (at least on Linux and Mac):Addition (see VonC's second comment): on Windows the file name is
%HOME%\_netrc
.Also read VonC's first comment in case you want to encrypt.
Another addition (see user137717's comment) which you can use if you have Git 1.7.10 or newer.
Cache your GitHub password in Git using a credential helper:
This also works on Linux, Mac, and Windows.
对于那些对前面的答案感到困惑的新手,您可以这样做:
它将响应类似的内容
然后您可以运行许多其他人建议的命令,但现在您从上面知道了您的名字和您的存储库,因此您可以剪切并粘贴< code>yourname/yourrepo.git 从上面进入:
For the uninitiated who are confused by the previous answers, you can do:
Which will respond with something like
Then you can run the command many other have suggested, but now you know yourname and yourrepo from above, so you can just cut and paste
yourname/yourrepo.git
from the above into:如果您使用 SSH 并且您的私钥是使用密码加密的,那么当您使用 Git 进行网络操作时,系统仍会提示您输入私钥的密码/密码 例如
推
、拉
和获取
。使用 ssh-agent 保存私钥密码/密码凭据
如果您想避免每次都输入密码,可以使用
ssh-agent
在每个终端会话中存储一次私钥密码凭据,正如我在我对无法打开到的连接的回答你的身份验证代理:在Windows msysgit Bash中,你需要评估
ssh-agent
的输出,但我不是确定您是否需要在其他开发环境和操作系统中执行相同的操作。ssh-add
在您的主.ssh
文件夹中查找名为id_rsa
的私钥,这是默认名称,但您可以传递文件路径到具有不同名称的密钥。终止代理
当您完成终端会话后,您可以使用终止标志
-k
关闭ssh-agent
:如
ssh-agent
手册:可选超时
此外,它还可以采用可选超时参数,如下所示:
其中
的格式为h
(对于)
小时,m
表示
分钟,依此类推。根据
ssh-agent
手册< /a>:请参阅此页面了解更多时间格式。
Cygwin 用户的安全警告
Cygwin 用户应意识到使用时存在的潜在安全风险Cygwin 中的 ssh 代理:
在引用的链接中:
If you're using SSH and your private key is encrypted with a passphrase, then you'll still be prompted to enter the passphrase/password for the private key when you do network operations with Git like
push
,pull
, andfetch
.Use ssh-agent to save the private key passphrase/password credentials
If you want to avoid having to enter your passphrase every time, you can use
ssh-agent
to store your private key passphrase credentials once per terminal session, as I explain in my answer to Could not open a connection to your authentication agent:In a Windows msysgit Bash, you need to evaluate the output of
ssh-agent
, but I'm not sure if you need to do the same in other development environments and operating systems.ssh-add
looks for a private key in your home.ssh
folder calledid_rsa
, which is the default name, but you can pass a filepath to a key with a different name.Killing the agent
When you're done with your terminal session, you can shutdown
ssh-agent
with the kill flag-k
:As explained in the
ssh-agent
manual:Optional timeout
Also, it can take an optional timeout parameter like so:
where
<timeout>
is of the format<n>h
for<n>
hours,<n>m
for<n>
minutes, and so on.According to the
ssh-agent
manual:See this page for more time formats.
Security warning for Cygwin users
Cygwin users should be aware of a potential security risk with using ssh-agent in Cygwin:
And at the cited link:
来源:设置 Git
以下命令将保存您的密码会在内存中保存一段时间(对于 Git 1.7.10 或更高版本)。
Source: Set Up Git
The following command will save your password in memory for some time (for Git 1.7.10 or newer).
当您使用 https 进行 Git pull 时推送时,只需为您的项目配置
remote.origin.url
即可,以避免每次推送时都输入用户名(或/和密码)。如何配置
remote.origin.url
:@Update - 使用
ssh
我认为使用
ssh
协议更好比https
更好的解决方案,尽管设置步骤稍微复杂一些。大致步骤:
ssh-keygen
,Windows上的msysgit
提供类似的命令。~/.ssh
。并通过 ssh-add 命令将其添加到 ssh 代理。remote.origin.url
更改为ssh
样式,例如[email protected]:myaccount/myrepo.git
提示:
@Update - 在
https
和ssh
协议之间切换。只需更改
remote.origin.url
就足够了,或者您可以直接编辑repo_home/.git/config
来更改值(例如使用vi
在 Linux 上)。通常我为每个协议添加一行,并使用
#
注释掉其中一个协议。例如
When you use https for Git pull & push, just configure
remote.origin.url
for your project, to avoid input username (or/and password) every time you push.How to configure
remote.origin.url
:@Update - using
ssh
I think using
ssh
protocol is a better solution thanhttps
, even though the setup step is a little more complex.Rough steps:
ssh-keygen
on Linux, on windowsmsysgit
provide similar commands.~/.ssh
. And add it to the ssh agent viassh-add
command.remote.origin.url
of the Git repository tossh
style, e.g.,[email protected]:myaccount/myrepo.git
Tips:
@Update - Switch between
https
andssh
protocol.Simply changing
remote.origin.url
will be enough, or you can editrepo_home/.git/config
directly to change the value (e.g usingvi
on Linux).Usually I add a line for each protocol, and comment out one of them using
#
.E.g.
如果您在 Github 帐户上启用了 2FA,则您的常规密码将无法用于此目的,但您可以生成个人访问令牌并在其位置上使用它。
访问
设置
->开发者设置
-> GitHub 中的个人访问令牌
页面 (https://github.com/settings/tokens /new),并生成具有所有 Repo 权限的新令牌:<图片src="https://i.sstatic.net/hEuYv.png" alt="生成 GitHub 个人访问令牌">
然后页面将显示新的令牌值。保存此值,并在推送到 GitHub 上的存储库时使用它代替密码:
If you've got 2FA enabled on your Github account, your regular password won't work for this purpose, but you can generate a Personal Access Token and use that in its place instead.
Visit the
Settings
->Developer Settings
->Personal Access Tokens
page in GitHub (https://github.com/settings/tokens/new), and generate a new Token with all Repo permissions:The page will then display the new token value. Save this value and use it in place of your password when pushing to your repository on GitHub:
您可以在 Git 中缓存您的 GitHub 密码:
只需按照 GitHub 的 官方文档。
按照上述链接中的说明进行操作后,您应该能够向存储库推送/拉取存储库,而无需每次都输入用户名/密码。
You can cache your GitHub password in Git:
Just follow the instructions from GitHub's official documentation.
After following the instructions from the above link, you should be able to push/pull to/from your repository without typing your username/password every time.
对我有用的是编辑
.git/config
并使用不用说,这是一种不安全的存储密码的方式,但在某些环境/情况下这可能不是问题。
What worked for me was to edit
.git/config
and useIt goes without saying that this is an insecure way of storing your password but there are environments/cases where this may not be a problem.
这是另一个选项:
显然,对于
您可以写:
大多数 shell,这将导致密码被缓存在历史记录中,因此请记住这一点。
Here's another option:
Instead of writing
You could write:
Obviously, with most shells this will result in the password getting cached in history, so keep that in mind.
对于 Mac OS,
Settings
->开发者设置
-> GitHub 中的个人访问令牌
页面 (https://github.com/settings/tokens /new),并生成一个具有所有 Repo 权限的新令牌显示密码
,然后粘贴您刚刚复制的令牌
。For Mac OS
Settings
->Developer Settings
->Personal Access Tokens
page in GitHub (https://github.com/settings/tokens/new), and generate a new Token with all Repo permissionsgithub.com
-> clickShow password
then paste thetoken
you just copied.这是我的工作解决方案,它也通过了 2FA。
https://github.com/settings/tokens
git remote set-url origin https://{yourAccountName}:{theCopiedToken}@github.com/{yourAccountName}/{repositoryName}.git
现在您已登录并可以推/拉等。
Here's my working solution which passes 2FA as well.
https://github.com/settings/tokens
git remote set-url origin https://{yourAccountName}:{theCopiedToken}@github.com/{yourAccountName}/{repositoryName}.git
Now you are logged in and can push/pull, etc.
如果 SSH 密钥或
.netrc
文件不适合您,那么另一个简单但不太安全的解决方案可能适合您:git-credential-store - 在磁盘上存储凭据的帮助程序:默认情况下,凭据将保存在文件
~/.git-credentials 中
。它将被创建并写入。请注意,使用此帮助程序会将您的密码未加密地存储在磁盘上,仅受文件系统权限的保护。如果这可能不是可接受的安全权衡。
If the SSH key or
.netrc
file did not work for you, then another simple, but less secure solution, that could work for you is git-credential-store - Helper to store credentials on disk:By default, credentials will be saved in file
~/.git-credentials
. It will be created and written to.Please note using this helper will store your passwords unencrypted on disk, protected only by filesystem permissions. If this may not be an acceptable security tradeoff.
我有同样的问题。
因此,我将项目中的 .git/config 文件更改
为
SSH 公钥,并将其添加到设置中的 Git 配置文件中。
对于 SSH 公钥:
I had the same issue.
So I changed the
.git/config
file from my project,to
and added the SSH public key to the Git profile which is in setting.
For the SSH public key:
如果您克隆了 HTTPS 而不是 SSH,并且在拉取、推送和获取时面临用户名和密码提示问题。您只需使用 UBUNTU
步骤 1 即可解决此问题:
移动到根目录
创建一个文件 .git-credentials
将此内容添加到该文件中
usename
password
和githosting URL
执行命令
然后立即 您将能够毫无麻烦地从您的存储库中拉出推送并获取所有详细信息。
If you have cloned HTTPS instead of SSH and facing issue with username and password prompt on pull, push and fetch. You can solve this problem simply for UBUNTU
Step 1:
move to root directory
create a file .git-credentials
Add this content to that file with you
usename
password
andgithosting URL
Then execute the command
Now you will be able to pull push and fetch all details from your repo without any hassle.
直接更新您的 Git 配置文件(如果您不想记住花哨的命令):
用您喜欢的文本打开
.git/config
文件编辑。它将位于您克隆的文件夹中或您在其中执行 git init 的存储库中。进入该存储库。.git
是一个隐藏文件夹,按 Ctrl + H 应显示隐藏文件夹,(ls -a
在终端)。以下是 .git/config 文件的示例。复制并粘贴这些行,并确保使用您的 Git 信息更新这些行。
将 URL 部分更改为 SSH 的以下格式:(
上述格式不会因各种 Git 远程服务器(如 GitHub 或 Bitbucket)而改变。如果您使用 Git 进行版本控制,情况是一样的):
注意:连接到远程 Git 存储库的 SSH 方式将要求您将公共 SSH 密钥添加到 Git 远程服务器(例如 GitHub 或 Bitbucket)。在设置页面中搜索 SSH 密钥)。
要了解如何生成 SSH 密钥,请参阅:
创建 SSH 密钥
Updating your Git configuration file directly (if you do not want to memorize fancy commands):
Open your
.git/config
file in your favorite text editor. It will be in the folder that you cloned or in the repository that you performedgit init
in. Go into that repository..git
is a hidden folder, and pressing Ctrl + H should show the hidden folder, (ls -a
in terminal).Below is a sample of the
.git/config
file. Copy and paste these lines and be sure to update those lines with your Git information.Change the URL part with the following format for SSH:
(The above formats do not change with various Git remote servers like GitHub or Bitbucket. It's the same if you are using Git for version control):
Note: The SSH way of connecting to a remote Git repository will require you to add your public SSH key to your Git remote server (like GitHub or Bitbucket. Search the settings page for SSH keys).
To know how to generate your SSH keys, refer to:
Creating SSH keys
这对我有用:
示例:
This is what worked for me:
Example:
你基本上有两个选择。
如果您在两台计算机上使用相同的用户,则需要将 .pub 密钥复制到您的 PC,以便 GitHub 知道您是同一用户。
如果您已为 PC 创建了新的 .pub 文件并希望将计算机视为不同的用户,则需要在 GitHub 网站上注册新的 .pub 文件。
如果这仍然不起作用,可能是因为 ssh 配置不正确,并且 ssh 无法找到密钥的位置。尝试
获取 SSH 失败原因的更多信息。
You basically have two options.
If you use the same user on both machines you need to copy the .pub key to your PC, so GitHub knows that you are the same user.
If you have created a new .pub file for your PC and want to treat the machines as different users, you need to register the new .pub file on the GitHub website.
If this still doesn't work it might be because ssh is not configured correctly and that ssh fail to find the location of your keys. Try
To get more information why SSH fails.
对于 Windows Git 用户,运行 git config --global credential.helper store 后,如果仍然提示输入密码,最好检查配置文件写入的位置,使用此命令
在我的在这种情况下,手动编辑配置文件“C:\Program Files\Git\mingw64\etc\gitconfig”并添加以下文本后,它起作用了。
For Windows Git users, after running
git config --global credential.helper store
, if it still prompts for a password, you'd better check where the configuration file is written to, using this commandIn my case, after manually editing configuration file 'C:\Program Files\Git\mingw64\etc\gitconfig', and adding the following text, it worked.
列出您当前的 SSH 密钥:
生成新的 SSH 密钥:
您应该在其中替换
[email ;protected]
使用您的 GitHub 电子邮件地址。
当提示
输入要保存密钥的文件
时,按输入。
输入密码后(无密码则为空)
- 只需按输入(输入空密码)。
再次列出您的 SSH 密钥:
文件
id_ed25519
和id_ed25519.pub
现在应该已添加。在后台启动 ssh-agent:
将您的 SSH 私钥添加到 ssh-agent:
接下来将公钥输出到终端屏幕:
将输出复制到剪贴板
(Ctrl + 插入)。
转到
https://github.com/
并使用您的帐户登录用户名和密码。
单击右上角的 GitHub 头像,然后单击设置。
在左侧窗格中单击SSH 和 GPG 密钥。
单击绿色按钮新建 SSH 密钥
并将公共 SSH 密钥粘贴到标记为 Key 的文本区域中。
使用描述性标题来说明您将在哪台计算机上使用
使用此 SSH 密钥。单击添加 SSH 密钥。
如果您当前的本地存储库是使用 http 和 用户名 创建的,
需要重新创建它才能兼容 SSH。
首先检查以确保您有一个干净的工作树
这样您就不会丢失任何工作:
然后
cd ..
到父目录并rm -fr
。最后克隆一个使用 SSH 而不是用户名/密码的新副本:
参考:
https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generate-a-new-ssh-key-and-adding-it-到 ssh 代理
https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-帐户
List your current SSH keys:
Generate a new SSH key:
where you should replace
[email protected]
with your GitHub emailaddress.
When prompted to
Enter a file in which to save the key
, pressEnter.
Upon
Enter passphrase (empty for no passphrase)
- just pressEnter (for an empty passphrase).
List the your SSH keys again:
The files
id_ed25519
andid_ed25519.pub
should now have been added.Start the ssh-agent in the background:
Add your SSH private key to the ssh-agent:
Next output the public key to the terminal screen:
Copy the output to the clipboard
(Ctrl + Insert).
Go to
https://github.com/<your-github-username>
and sign in with yourusername and password.
Click your GitHub avatar in the upper-right corner, and then Settings.
In the left pane click SSH and GPG keys.
Click the green-colored button New SSH key
and paste the public SSH key into the textarea labeled Key.
Use a descriptive Title that tells from what computer you will
use this SSH key. Click Add SSH key.
If your current local repository was created with http and username,
it needs to be recreated it so as to become SSH compatible.
First check to make sure that you have a clean working tree
so that you don't lose any work:
Then
cd ..
to the parent directory andrm -fr <name-of-your-repo>
.Finally clone a fresh copy that uses SSH instead of username/password:
References:
https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account
HTTPS 更新:
GitHub 推出了一个适用于 Windows 的新程序,可在您使用 HTTPS 时存储您的凭据:
使用方法:
从 此处
运行该程序后,它将编辑您的
.gitconfig
文件。如果您有多个,请重新检查它是否编辑了正确的.gitconfig
。如果没有编辑正确的内容,请将以下内容添加到您的.gitconfig
<前><代码>[凭据]
helper = !'C:\\Path\\To\\Your\\Downloaded\\File\\git-credential-winstore.exe'
注意
[credential]
后面的换行符。这是必需的。打开命令行客户端并尝试一次
git push origin master
。如果它要求您输入密码,请输入密码即可完成。密码已保存!Update for HTTPS:
GitHub has launched a new program for Windows that stores your credentials when you're using HTTPS:
To use:
Download the program from here
Once you run the program, it will edit your
.gitconfig
file. Recheck if it edited the correct.gitconfig
in case you have several of them. If it didn't edit the correct one, add the following to your.gitconfig
NOTE the line break after
[credential]
. It is required.Open up your command line client and try
git push origin master
once. If it asks you for a password, enter it and you're through. Password saved!您需要执行两个步骤 -
gitmoteremoveorigin
gitremoteaddorigin[电子邮件受保护]:NuggetAI/nugget.git
请注意,Git URL 是 SSH URL,而不是 HTTPS URL...您可以从此处选择:
< img src="https://i.sstatic.net/kmjwG.png" alt="在此处输入图像描述">
You need to perform two steps -
git remote remove origin
git remote add origin [email protected]:NuggetAI/nugget.git
Notice the Git URL is a SSH URL and not an HTTPS URL... Which you can select from here:
截至 2021 年,HTTPS 遥控器将有一个安全、用户友好的跨平台解决方案。不再需要输入密码!不再需要 SSH 密钥!不再需要个人访问令牌!
安装 GitHub 开发的 Git Credential Manager (下载)。它支持对 GitHub、BitBucket、Azure 和 GitLab 进行无密码浏览器内 OAuth 身份验证。这意味着您可以在 GitHub 和其他平台上启用双因素身份验证,从而大大提高您的安全性账户。
当您推送时,您可以选择身份验证方法:
在 Linux 上,需要进行少量设置。以下将凭据在内存中缓存 20 小时,因此您每天最多必须进行一次身份验证。
熟悉 gnome-keyring 或 KWallet 的高级用户可能更喜欢 将凭证存储更改为 libsecret。
外观配置 (docs< /a>):
As of 2021, there is a secure user-friendly cross-platform solution for HTTPS remotes. No more typing passwords! No more SSH keys! No more personal access tokens!
Install Git Credential Manager developed by GitHub (downloads). It supports passwordless in-browser OAuth authentication to GitHub, BitBucket, Azure and GitLab. This means you can enable two-factor authentication on GitHub and the other platforms, greatly improving the security of your accounts.
When you push, you are offered a choice of authentication methods:
On Linux, a tiny bit of setup is required. The following caches credentials in memory for 20 hours, so you have to authenticate at most once per day.
Power users familiar with gnome-keyring or KWallet may prefer to change the credential store to libsecret.
Cosmetic configuration (docs):
如果您在 Windows 下使用 Git(例如 Git Bash)
(如果您不想从 HTTPS 切换到 SSH),您也可以使用 Windows 版 Git Credential Manager
此应用程序将为您保留用户名和密码...
If you are using Git (for example, Git Bash) under Windows
(and if you don't want to switch from HTTPS to SSH), you could also use Git Credential Manager for Windows
This application will keep the username and password for you...
如果您遇到 $ git Push 代码问题,要求输入用户名 && , 密码请按照以下步骤操作:
if you experience $ git push code issues requesting for username && password follow the procedure below:
正如许多用户所说,您只需将 Git 存储库 URL 从 HTTPS 更改为 SSH 即可。
如果您尚未在计算机中生成 SSH 密钥,则必须执行此操作。
作为附加信息,进行此更改后我仍然收到相同的错误:
就我而言,问题在于我使用 Windows Shell 执行 ngh 命令;由于此命令应打开一个提示来请求 SSH 短语,而 Windows Shell 不会打开此类提示,因此身份验证失败。
所以,我只需打开 Git shell 并在那里执行 ngh 命令,每次要求时将 SSH 短语放入提示符中,然后“瞧”......它工作得很好!
As many users has said, you just have to change your Git repository URL from HTTPS to SSH.
If you haven't generated a SSH key in your machine, then your are going to have to do it.
Just as an additional information, after doing this change I still was getting the same error:
In my case, the problem was that I was using the Windows Shell to execute the ngh command; since this command should open a prompt to request the SSH phrase and the Windows Shell doesn't open these kinds of prompts, the authentication just failed.
So, I just had to open the Git shell and execute the ngh command there, put the SSH phrase in the prompt every time it asked for it and "voilà"... It just worked fine!
你的 git 和/或 SSH 版本太旧了
我在运行 Snow Leopard 的 2010 Macbook Pro 上受到 ssh 和 git 的影响,总是提示输入密码。
最初,我无法 ssh 进入我的服务器。
我在我的服务器 (
/etc/ssh/sshd_config
) 上启用了HostKeyAlgorithms +ssh-rsa,ssh-dss
,我将 git 存储库和 ssh 托管到我的帐户中。通过这一更改,我能够使用用户名和密码通过 ssh 连接到 git。作为参考,OS X 10.6.8 上 ssh 和 git 的最新版本是:
git: 1.7.5.4
ssh: OpenSSH_5.2p1
我尝试添加 DSA 密钥,但那没用。我还考虑过更新 RSA1 密钥,但看起来我的 SSH 版本太旧了。
我在 Homebrew 中查找了雪豹,但遇到了证书问题。
我的解决方案是安装 MacPorts for Snow Leopard https://github.com/macports/macports-base/releases/download/v2.8.1/MacPorts-2.8.1-10.6-SnowLeopard.pkg
我安装了 xcode 4.2 更新,可能是很难找到;不确定是否有必要。安装 MacPorts 后,运行
您可能必须启用 rsync,但输出会告诉您如何启用。
我的 git 版本现在是
2.41.0
,ssh 版本是OpenSSH_9.3p1
。我重新创建了一个 4096 位 rsa 密钥并将其复制到我的服务器(和 github),现在可以使用ssh
和git Push
而无需任何密码提示!希望这对处于我位置的其他人有所帮助。
编辑:Gentoo 提到,从 OpenSSH 8.8 开始,对 RSA 1 的支持被禁用(我的服务器是
OpenSSH_9.3p1
)。可以通过添加以下内容来重新启用它:如果您使用的是 PuTTY < 0.75,你就会受到这个影响。
Your git and/or SSH version is too old
I was affected by both ssh and git always prompting for passwords on my 2010 Macbook Pro running Snow Leopard.
Originally, I was unable to ssh into my server.
I had enabled
HostKeyAlgorithms +ssh-rsa,ssh-dss
on my server (/etc/ssh/sshd_config
) which I host my git repos and ssh into my accounts. With that change, I was able to use a username and password to connect to git and through ssh.For reference the latest versions of ssh and git on OS X 10.6.8 are:
git: 1.7.5.4
ssh: OpenSSH_5.2p1
I tried adding a DSA key, but that didn't work. I also looked into updating the RSA1 key, but it looked like my SSH version was simply too old.
I looked into Homebrew for snow leopard, but got certificate issues.
My solution is to install MacPorts for Snow Leopard https://github.com/macports/macports-base/releases/download/v2.8.1/MacPorts-2.8.1-10.6-SnowLeopard.pkg
I had the xcode 4.2 update installed which may be hard to find; not sure if that is necessary. Once MacPorts is installed, run
You may have to enable rsync, but the output will tell you how.
My versions are now
2.41.0
for git andOpenSSH_9.3p1
for ssh. I recreated a 4096 bit rsa key and copied it to my server (and to github) and can now bothssh
andgit push
without any password prompting at all!Hope this helps out others in my position.
Edit: Gentoo mentioned that since OpenSSH 8.8, support for RSA 1 is disabled (my server being
OpenSSH_9.3p1
). It can be re-enabled by adding this:If you are using PuTTY < 0.75, you will be affected by this.