简体   繁体   English

无法通过ssh使用公钥身份验证方法进行连接

[英]Unable to connect via ssh with public key authentication method

On my Windows 10, I am running into the problem of not being able to connect to m Vagrant virtual machine via ssh user with public key authentication method at git bash using command such as 在我的Windows 10上,我遇到了以下问题:无法使用ssh用户通过git bash使用诸如以下命令的公钥身份验证方法通过ssh用户连接到m Vagrant虚拟机

$ ssh -v lauser@127.0.0.1 -p 2222 -i ~/.ssh/id_rsa

I would be prompted for password, as if the public key I copied to in the ~/.ssh/Authorized_keys file inside the vm were not seen. 系统将提示我输入密码,好像没有看到我复制到vm内〜/ .ssh / Authorized_keys文件中的公钥。 Meanwhile,the password authentication method works, as well as 'vagrant ssh'. 同时,密码验证方法以及“ vagrant ssh”均有效。 I have made sure to 我确保

  1. create key pairs locally, create a .ssh directory at the remote, and add pub key string to the remote's .ssh /authorized_keys file; 在本地创建密钥对,在远程上创建.ssh目录,并将发布密钥字符串添加到远程的.ssh / authorized_keys文件中; both the .ssh and the .ssh /authorized_keys file are owned by the user(lauser), and set at 700 and 644 .ssh和.ssh / authorized_keys文件都由用户(lauser)拥有,并设置为700和644

  2. edit the /etc/ssh/sshd_config file on vm to use RSAAuthentication yes PubkeyAuthentication yes and restarted the sshd server (with 'sudo service ssh restart'). 在vm上编辑/ etc / ssh / sshd_config文件以使用RSAAuthentication yes PubkeyAuthentication yes并重新启动sshd服务器(使用“ sudo service ssh restart”)。

  3. verify that firewall has been disabled temporarily to eliminate any complication. 确认已暂时禁用防火墙以消除任何复杂情况。

  4. verify that there is only one vm running, all others are either in 'suspend' or 'halt' mode. 确认只有一个虚拟机正在运行,其他所有虚拟机都处于“挂起”或“暂停”模式。

  5. confirm the file type by 'file ~/.ssh/authorized_keys', and get confirmation '~/.ssh/authorized_keys: OpenSSH RSA public key' 通过“ file〜/ .ssh / authorized_keys”确认文件类型,并获得“〜/ .ssh / authorized_keys:OpenSSH RSA公钥”确认

  6. verify that the keys match by comparing the output from 'sudo cat ~/.ssh/authorized_keys' in vm and the output from ' cat ~/.ssh/id_rsa.pub' at the local. 通过比较vm中'sudo cat〜/ .ssh / authorized_keys'的输出与本地的'cat〜/ .ssh / id_rsa.pub'的输出,验证密钥是否匹配。

but still I get Permission denied (publickey) when trying to connect through public key authentication. 但是在尝试通过公钥身份验证进行连接时,仍然出现权限被拒绝(公钥)的情况。

It sounds like you've done everything correctly so far. 听起来您到目前为止已经正确完成了所有操作。 When I run in to this problem, it's usually due to directory permissions on the target user's home directory (~), ~/.ssh or ~/.ssh/authorized_keys. 当我遇到此问题时,通常是由于目标用户的主目录(〜),〜/ .ssh或〜/ .ssh / authorized_keys具有目录权限。

See this answer on SuperUser . 在SuperUser上查看此答案

I faced same challenges when the home directory on the remote did not have correct privileges. 当遥控器上的主目录没有正确的特权时,我也面临着同样的挑战。 Changing permissions from 777 to 744 helped me 将权限从777更改为744帮助了我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM