ssh -i 权限被拒绝公钥

ssh -i 权限被拒绝公钥

我正在尝试以主机用户身份进行 SSH。

我已经使用 ssh-keygen 为gitlab主机上的用户创建了 ssh 密钥,并将公钥复制到我的本地id_rsa.pub机器,~/.ssh/authorized_keys同时将私钥复制id_rsa到本地机器。

当我尝试使用以下命令进行 ssh 时:

ssh -v -i id_rsa [email protected]

我收到以下权限被拒绝错误:

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 67.205.XXX.XXX [67.205.XXX.XXX] port 22.
debug1: Connection established.
debug1: identity file id_rsa type -1
debug1: identity file id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.8
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.8 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 67.205.XXX.XXX:22 as 'gitlab'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
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:ERK9s4ZkT4m95jq0sejB38PNAMGaLdIQB98SNqWQDfg
debug1: Host '67.205.XXX.XXX' is known and matches the ECDSA host key.
debug1: Found key in /Users/angad/.ssh/known_hosts:46
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: /Users/angad/.ssh/id_rsa RSA SHA256:/xJTv6gRH+xBW9Q+SnwlkRVada4tMESKT+z1LT2zu18 agent
debug1: Will attempt key: id_rsa  explicit
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 public key: /Users/angad/.ssh/id_rsa RSA SHA256:/xJTv6gRH+xBW9Q+SnwlkRVada4tMESKT+z1LT2zu18 agent
debug1: Authentications that can continue: publickey
debug1: Trying private key: id_rsa
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).

不确定如何进一步调试。

答案1

弄清楚了。

public_key 需要存在于生成 ssh-keypair 的用户/home/<user>/.ssh/authorized_keys<user>

答案2

您必须在执行 .ssh 命令的用户的 .ssh/ 目录中拥有 id_rsa.pub 和 id_rsa。在远程主机上,您必须将 id_rsa.pub 复制为您代表其进行 ssh 的用户主目录中的 .ssh/authorized_keys。

相关内容