gpt4 book ai didi

linux - 通过私钥进行服务器到服务器的 ssh -- 权限被拒绝(公钥)

转载 作者:太空宇宙 更新时间:2023-11-04 05:18:51 27 4
gpt4 key购买 nike

我知道这个问题可能是最被否决的问题列表中的一个,但尽管如此,从早上开始就一直困扰着这个问题,因此值得一试,以获得社区的积极回应。我已经浏览了各种已经提出的问题及其解决方案,但我猜它不起作用。

我正在关注https://docs.gitlab.com/ee/ci/examples/deployment/composer-npm-deploy.html将部署脚本从 gitlab runner 写入我的服务器。因此,运行程序(基于 ubuntu/docker)需要将文件传输到我的服务器,并且因为运行程序是动态的(在本例中 - 两者都是 Droplet)

  • 我正在使用我的服务器的私钥
  • 通过运行将私钥放入运行器中

eval $(ssh-agent -s)

nano /root/.ssh/id_rsa_sid (pasted the private key content from my server (.ssh/id_rsa))

ssh-add /root/.ssh/id_rsa_sid

Identity added: /root/.ssh/id_rsa_sid (/root/.ssh/id_rsa_sid)

现在,当我执行 ssh -v root@serverip 时,我收到权限被拒绝(公钥)的消息。 (我也尝试了 -i key 文件路径标志 - 相同的结果)

root@ubuntu-512mb-sgp1-01:~/.ssh# ssh -v -i id_rsa_sid root@serverip
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 128.xxx.xxx.xxx [128.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file id_rsa_sid type -1
debug1: key_load_public: No such file or directory
debug1: identity file id_rsa_sid-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: Remote protocol version 2.0, remote software version
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 128.199.253.228:22 as 'root'
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:/El3UFF60r6/qNAwvfyIzx6Cf6N2YuXed/UU5QWEP1Q
debug1: Host '128.199.253.228' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
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: /root/.ssh/id_rsa_sid
debug1: Authentications that can continue: publickey
debug1: Trying private key: id_rsa_sid
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

如您所见,它尝试将该文件作为公钥和私钥,但失败了。

我去服务器查看日志:

cat /var/log/auth.log

Jul  5 13:13:16 docker-512mb-sgp1-01 sshd[2371]: Connection closed by 128.yyy.yyy.yy port 43292 [preauth]

请让我知道我做错了什么,或者如果可以的话,请告诉我正确的资源。

最佳答案

对于像我这样的人(来这里寻找答案的人)

做了一些故障排除,发现这是一个相当愚蠢的错误。

将服务器的公钥添加到其授权 key 文件中。这样就可以了:-)

谢谢

关于linux - 通过私钥进行服务器到服务器的 ssh -- 权限被拒绝(公钥),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44929026/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com