SSH 不断要求输入密码

SSH 不断要求输入密码

我想使用两种使用公钥认证的不同服务,而不必总是输入我的密码。

我想要的是:

  • git pull无需输入我的登录名/密码或密码短语即可输入内容
  • gcloud [...] ssh [...]无需每次都输入密码即可打字。

截至今日:

  • git pull不要求我输入我的凭证,它们存储在里面~/.ssh/id_rsa~/.ssh/id_rsa.pub
  • gcloud ... ssh ...总是要求我输入密码:

$ gcloud... ssh...

sign_and_send_pubkey:签名失败:代理拒绝操作

输入密钥“/home/BeChillerToo/.ssh/google”的密码:

这是我的内容~/.ssh/config

IdentityFile ~/.ssh/google
IdentityFile ~/.ssh/id_rsa

以及内容/etc/ssh/ssh_config

Host *
PasswordAuthentication yes
SendEnv LANG LC_*
HashKnownHosts yes
GSSAPIAuthentication yes

编辑:我的钥匙似乎添加得不好。

ssh-add -l这是我启动后的结果:

2048 SHA256:+nCvs...CUM+DHqA4 chill@laptop (RSA)
4096 SHA256:bTgKQM...ok [email protected] (RSA)
4096 SHA256:92d3Wy...jc [email protected] (RSA)

然后我添加google-compute-engine密钥之后:

2048 SHA256:+nCvs...CUM+DHqA4 /home/chill/.ssh/google_compute_engine (RSA)
4096 SHA256:bTgKQM...ok [email protected] (RSA)
4096 SHA256:92d3Wy...jc [email protected] (RSA)

相关的关键[电子邮件保护]是我用于 Github 的那个,因此我不需要向 提供凭据git pull

chill@laptop我怀疑第一个键(从 切换到 的 键/home/chill/.ssh/google_compute_engine)是导致问题的键gcloud

$ gcloud compute ... ssh ...

sign_and_send_pubkey: signing failed: agent refused operation
Enter passphrase for key '/home/chill/.ssh/google_compute_engine': 

答案1

使用ssh 代理. 在 X 环境中GNOME 钥匙圈或者KDE 钱包可以自动处理密钥。在控制台环境中,ssh-agent像这样启动:

$ eval $(ssh-agent)

## The output without the eval will look like this:
$ ssh-agent
ssh-agent 
SSH_AUTH_SOCK=/tmp/ssh-hvcwJQnSOHOi/agent.125894; export SSH_AUTH_SOCK;
SSH_AGENT_PID=125895; export SSH_AGENT_PID;
echo Agent pid 125895;

启动后ssh-agent(使用eval)。您可以使用ssh 添加

$ ssh-add ~/.ssh/google
$ ssh-add ~/.ssh/id_rsa

使用当前版本的 SSH,你还可以添加选项添加密钥到代理~/.ssh/config文件:

## ~/.ssh/config
AddKeysToAgent yes

如果设置了SSH_AUTH_SOCK环境变量,这将自动将密钥添加到代理。SSH_AGENT_PID

另请查看此帖子sign_and_send_pubkey:签名失败:代理拒绝操作错误。

答案2

@Simon Sudler 的答案和另一个答案的组合:

1. Your home directory ~, your ~/.ssh directory and the ~/.ssh/authorized_keys file on the remote machine must be writable only by you: rwx------ and rwxr-xr-x are fine, but rwxrwx--- is no good¹, even if you are the only user in your group (if you prefer numeric modes: 700 or 755, not 775).

2. If ~/.ssh or authorized_keys is a symbolic link, the canonical path (with symbolic links expanded) is checked.
Your ~/.ssh/authorized_keys file (on the remote machine) must be readable (at least 400), but you'll need it to be also writable (600) if you will add any more keys to it.

3. Your private key file (on the local machine) must be readable and writable only by you: rw-------, i.e. 600.

(权限具体回答)

https://unix.stackexchange.com/questions/36540/why-am-i-still-getting-a-password-prompt-with-ssh-with-public-key-authentication

很快就解决了我的问题。

相关内容