不久前,我能够使用 SSH 连接到我的服务器,但突然它停止工作了。
我正在尝试命令:ssh -i "mykey.pem" ubuntu@server-ip
并且 Ec2 抛出异常
Permission denied (publickey).
当我尝试使用 SFTP 连接时,出现了错误
Error: Server sent disconnect message
Error: type 2 (protocol error):
Error: "Too many authentication failures"
Error: Could not connect to server
然后我使用 -v 模式启动该命令,以下是输出。你们能帮我解决这个问题吗?我完全为此而烦恼。
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to x.x.x.x [x.x.x.x] port 22.
debug1: Connection established.
debug1: identity file mykey.pem type -1
debug1: identity file mykeypem-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: match: OpenSSH_7.6p1 Ubuntu-4ubuntu0.3 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to x.x.x.x:22 as 'ubuntu'
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:6NiTFBw2gv2t9lxZJlAxMbNJ7Ih2WcEmp2S3McfuFe0
debug1: Host 'x.x.x.x' is known and matches the ECDSA host key.
debug1: Found key in /Users/myuser/.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: Will attempt key: mykey.pem explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: mykey.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).
答案1
我所面临的问题的根本原因是我的一名团队成员将/home/user
目录的权限更改为777
。
这把一切都破坏了。
正确的权限是:
/home/user 600
/home/user/.ssh 700
/home/user/.ssh/authorised_keys 0600
希望这对其他人有帮助。