SSH 尝试时“权限被拒绝(公钥)”和“key_load_public:没有这样的文件或目录”

tur*_*rnt 5 ssh ssh-keys

我在运行时不断收到以下错误ssh -v -i privatekey user@server.org

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 chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <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).
Run Code Online (Sandbox Code Playgroud)

我不明白出了什么问题。我已经正确复制了我的公钥并编辑了私钥文件的权限以确保它的安全。

Sli*_*eer 5

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

  1. 检查 SSH 上的日志。
  2. 你是如何将公钥传输到服务器的?始终使用ssh-copy-id以确保权限。用户家目录、.ssh 目录和服务器端的authorized_keys 文件都有严格的权限要求。(参见man sshdauthorized_keys)。
  3. 检查服务器配置文件,/etc/ssh/sshd_config也许服务器只允许特定用户或组登录。

  • 这对我有用,我尝试登录的用户在 `/etc/ssh/sshd_config` 中丢失 (2认同)