如何告诉 git 不要使用 rsa 密钥而是使用用户名+密码

如何告诉 git 不要使用 rsa 密钥而是使用用户名+密码

我猜我弄乱了我的 ssh 配置。

最近我无法再克隆本地存储库。git 存储库似乎同时接受公钥和密码,但它没有让我选择两个选项之一,而是尝试使用错误的 RSA 密钥进行连接,从而导致出现以下消息:

Received disconnect from myRemoteComputer : Too many authentication failures for myUsername
fatal: Could not read from remote repository.

当我 ssh 到那台计算机时也会发生同样的情况

$ssh -v myRemoteComputerIP
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/myUsername/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: myUsername@cvg04
Received disconnect from myRemoteComputerIP: Too many authentication failures for myUsername

所以肯定出了问题,因为最近两个命令都正常工作。我基本上需要告诉sshgit使用用户名和密码,而不是随机选择错误的“RSA 密钥”。有人知道如何修复这个问题吗?

另外,我ssh-add最近根据论坛的建议执行了一些命令,但这也许是问题的一部分......

答案1

检查你的~/.ssh/config。如果你想使用密码验证,你可以像这样在那里进行设置:

Host myRemoteComputerIP
  PubkeyAuthentication no

它永远不会尝试针对该主机进行公钥认证。


当我必须使用 rsa 密钥和用户名/密码身份验证来连接两个不同的用户名时,该怎么办?

您可以在以下位置使用别名ssh_config

Host alias1
  Hostname myRemoteComputerIP
  PubkeyAuthentication no
  User user1
Host alias2
  Hostname myRemoteComputerIP
  # PubkeyAuthentication yes # is default
  User user2

然后使用ssh alias1和连接ssh alias2

答案2

使用 https 进行克隆,它会始终要求输入密码。例如:

git clone https://github.com/my_company/myrepo.git

相关内容