错误:权限被拒绝(公钥)和解决方案

ssh or similar applications use Public and Private Key mechanism in order to authenticate and authorize given users. We have all ready examined Key based authentication and authorization in previous tutorials. Permission denied(public key) error is generally occurs for can not reading Public and Private key properly to authenticate to remove server. In this tutorial we will learn general causes and solutions.

ssh或类似的应用程序使用公钥和私钥机制来对给定的用户进行身份验证和授权。 在前面的教程中,我们已经准备好检查基于密钥的身份验证和授权。 权限被拒绝(公钥)错误通常是由于无法正确读取公钥和私钥以进行身份​​验证以删除服务器而发生的。 在本教程中,我们将学习一般原因和解决方案。

故障排除 (Troubleshooting)

We will start with a simple troubleshooting. When we try to connect a server or a service with ssh we can print detailed steps with verbose option. Verbose or debug option is expressed with -vv. More v‘s like -vvv will provide more detailed about the steps.

我们将从简单的故障排除开始。 当我们尝试通过ssh连接服务器或服务时,可以使用详细选项打印详细步骤。 详细或调试选项用-vv表示。 像-vvv这样的更多v会提供有关步骤的更多详细信息。

$ ssh -vvv 192.168.153.185
Troubleshooting
Troubleshooting
故障排除

解决方案:更改SSH密钥权限(Solution: Change SSH Key Permissions)

One of the most probable cause is read permissions. If we do not have required permissions to read SSH public and private key we can get this error. Another variation is the public and private key pairs owner ship may be changed to another user. First we will give the read permission to the current owner user.

最可能的原因之一是读取权限。 如果我们没有读取SSH公钥和私钥所需的权限,则会收到此错误。 另一个变体是公用密钥对和私有密钥对所有者可能会更改为另一个用户。 首先,我们将授予当前所有者用户的读取权限。

$ sudo chmod -R 600 .ssh
Solution: Change SSH Key Permissions
Solution: Change SSH Key Permissions
解决方案:更改SSH密钥权限

AND we will change the owner to the user ismail in this case

并且在这种情况下,我们将所有者更改为用户ismail

$ sudo chown -R ismail:ismail .ssh

解决方案:明确指定SSH私钥 (Solution:Specify SSH Private Key Explicitly)

Another problem may be the keys can be located different than default PATH or directory. The ssh or similar client may not be found the keys and use to for authentication and authorization. We can explicitly specify the Public and Private ssh keys with -i option.

另一个问题可能是键可以位于与默认PATH或目录不同的位置。 可能找不到ssh或类似客户端的密钥,并且无法将其用于身份验证和授权。 我们可以使用-i选项显式指定Public和Private ssh密钥。

$ ssh -i .ssh/id_rsa 192.168.153.185
Solution:Specify SSH Key Explicitly
Solution:Specify SSH Key Explicitly
解决方案:明确指定SSH密钥

解决方案:授权密钥文件配置(Solution:AuthorizedKeysFile Configuration)

ssh server configuration hold on local user home or in the /etc/ssh/sshd_config . We can check the authorized key files location with AuthorizedKeysFile like below.

ssh server配置保留在本地用户主目录或/etc/ssh/sshd_config 。 我们可以使用AuthorizedKeysFile来检查授权密钥文件的位置,如下所示。

AuthorizedKeysFile %h/.ssh/authorized_keys

解决方案:启用密码验证 (Solution: Enable PasswordAuthentication)

Another solution may be enabling Password based authentication. Key based authentication provides more secure way to authentication but may not suitable in some cases. We can enable password based authentication with PasswordAuthentication option in /etc/ssh/sshd_config file

另一个解决方案可能是启用基于密码的身份验证。 基于密钥的身份验证提供了更安全的身份验证方式,但在某些情况下可能不适合。 我们可以使用/etc/ssh/sshd_config文件中的PasswordAuthentication选项启用基于密码的身份验证

PasswordAuthentication yes
LEARN MORE  Linux SCP Command Usage With Examples
通过示例了解更多Linux SCP命令用法

翻译自: https://www.poftut.com/error-permission-denied-publickey-and-solution/

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值