服务器 centos7
客户端 ubuntu 18lts
当我尝试使用 rsa auth 远程访问服务器时,收到以下调试日志:
tony@ubuntu18:~$ ssh -v [email protected] -i .ssh/id_rsa
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 10.0.2.6 [10.0.2.6] port 22.
debug1: Connection established.
debug1: identity file .ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file .ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 10.0.2.6:22 as 'tony'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:RF83jXuKjMu0X6yUhqsFmgm7lIzpBc/1OwSfBnbSnrs
debug1: Host '10.0.2.6' is known and matches the ECDSA host key.
debug1: Found key in /home/tony/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)
debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:41zM34vDTpUwzUiS6B6saal7Skkukj839jE2xTlRZk8 .ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
答案1
我想我找到原因了...authorized_keys 文件必须由用户拥有,但在您的情况下,它由 root 拥有...由于 sshd 是在用户上下文中启动的,因此 sshd 无法读取 authorized_keys 文件!sudo chown allen:allen .ssh/authorized_keys
在服务器上尝试...
如果您不确定是否粘贴了错误的公钥 - 以下命令将为您的私钥文件“重新生成”公钥。执行:
ssh-keygen -y -f <private key file>
并将该行与您的 authorized_keys 文件进行比较。来源:https://stackoverflow.com/questions/274560/how-do-you-test-a-public-private-dsa-keypair