我正在尝试使用密钥设置 ssh 访问 - 我已将我的公钥添加到服务器上的 .ssh 目录中。我也重新启动了服务器上的 ssh 服务。当我从本地计算机登录到服务器时,我收到一条拒绝消息(复制如下 - 使用 v 标志)。我从问题中替换了用户名和 IP 地址。知道我可能做错了什么吗?
ssh -v [email protected]
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to xxx.xxx.xxx.xxx [xxx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA dd:e7:a3:31:60:21:c5:90:24:b5:11:65:43:d8:cd:a0
debug1: Host 'xxx.xxx.xxx.xxx' is known and matches the ECDSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
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: /home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Trying private key: /home/user/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
确保 .ssh 目录和 authorized_keys 的权限正确,如 .ssh 的 0700 和 ~/.ssh/authorized_keys 的 0600。如果没有,请先解决此问题。
确保在您的服务器上启用了密钥身份验证,但默认情况下应该没问题,请检查您的 sshd_config 进行确认。
检查服务器、RedHat / Fedora 和大多数 Linux 发行版上的日志文件,您可以在 /var/log/secure 中找到它们
您无需重新启动 sshd 守护程序即可让他知道您新添加的密钥。
最好使用 ssh-copy-id 将您的密钥复制到服务器。
看这里,它是特定于 Ubuntu 的,但是当我们谈论 OpenSSH 时,它仍然可以工作:
https://help.ubuntu.com/community/SSH/OpenSSH/Keys
就我而言,我必须将我创建的 id_rsa 文件(私钥)复制到 ssh 进程正在寻找的 id_dsa 文件(之前未创建)。使用 ssh -v 命令帮助我解决了这个问题。