我最近尝试通过ssh ssh root@360productions.com
登录我的Droplet,但无法获得对服务器的任何访问权限。我一直收到错误Permission denied (publickey).
ssh-add
添加id_rsa
无效 ssh-add
无效 cat ~/.ssh/id_rsa.pub | ssh root@360productions.com "cat >> ~/.ssh/authorized_keys"
无效 我认为这个问题与保存在我的机器上不再拥有的公钥的液滴有关。如何通过ssh成功再次访问服务器?
当我运行调试时,我得到了这个输出。试图欺骗这里出了什么问题。
OpenSSH_7.5p1, LibreSSL 2.5.4
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: /etc/ssh/ssh_config line 102: Applying options for *
debug1: Connecting to 360productions.com [2604:a880:2:d0::45:a001] port 22.
debug1: Connection established.
debug1: identity file /Users/Basecamp/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Basecamp/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Basecamp/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Basecamp/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Basecamp/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Basecamp/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Basecamp/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/Basecamp/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 360productions.com:22 as 'Basecamp'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:CI6GGFMyR17U6SoUOCwCMXBXc6JtxsuAxRX5Wdvt79Q
debug1: Host '360productions.com' is known and matches the ECDSA host key.
debug1: Found key in /Users/Basecamp/.ssh/known_hosts:30
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
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/Basecamp/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/Basecamp/.ssh/id_dsa
debug1: Trying private key: /Users/Basecamp/.ssh/id_ecdsa
debug1: Trying private key: /Users/Basecamp/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
如何使用正确的公钥更新服务器?
答案 0 :(得分:2)
您应该使用ssh -i选项指定私钥。例如:
ssh -i /home/user/.ssh/id_rsa user@host.com
如果您的授权密钥没有相应的公钥,您可以通过Digital Ocean网站登录。有一个“访问”链接,允许您输入密码。您可以从那里修复authorized_keys文件。
同样,您需要将公钥(id_rsa.pub)添加到服务器上的authorized_keys,并使用ssh的-i选项指定私钥(id_rsa)。
如果没有其他公钥并且使用-i指定,您将无法使用ssh来附加新公钥。
另外,您可能需要指定/root/.ssh/authorized_keys,我不确定〜/ .ssh是否可以使用root。还要验证该文件是否归root所有,并具有600个权限。