在SSH尝试时,用“key_load_public:没有这样的文件或目录”的“权限被拒绝(publickey)”

运行ssh -v -i privatekey [email protected]时,我一直收到以下错误。

 OpenSSH_6.9p1, LibreSSL 2.1.8 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 21: Applying options for * debug1: Connecting to server.org [XXX.XXX.XXX.XXX] port 22. debug1: Connection established. debug1: identity file privatekey type 1 debug1: key_load_public: No such file or directory debug1: identity file privatekey-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.9 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 pat OpenSSH* compat 0x04000000 debug1: Authenticating to server.org:22 as 'user' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client [email protected] <implicit> none debug1: kex: client->server [email protected] <implicit> none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ssh-rsa SHA256:ig8ZTpASPM0W/drPBHPzcUIr+NtqzOKvVAvihnbaNuc debug1: Host 'server.org' is known and matches the RSA host key. debug1: Found key in /Users/XXX/.ssh/known_hosts:3 debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: Roaming not allowed by server debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Offering RSA public key: ysm debug1: Authentications that can continue: publickey debug1: Offering RSA public key: /Users/XXX/.ssh/id_rsa debug1: Authentications that can continue: publickey debug1: No more authentication methods to try. Permission denied (publickey). 

我不明白什么是错的。 我已经正确地复制了公钥并在私钥文件上编辑了权限,以确保它的安全。

“拒绝权限”错误意味着服务器拒绝您的连接。

  1. 检查SSH上的日志。
  2. 你是如何将公钥传输到服务器的? 总是使用ssh-copy-id来确定权限。 用户主目录, 服务器端的.ssh目录和authorized_keys文件都有严格的权限要求。 (请参阅关于authorized_keys的man sshd )。
  3. 检查服务器configuration文件/etc/ssh/sshd_config可能服务器只允许login到特定的用户或组。