我已配置 gpg-agent 来连接到 ssh,但由于某种原因我无法使用设备地址进行连接。在〜/ .ssh /配置我添加了
Host openwrt
Hostname 192.168.1.1
User root
现在使用ssh openwrt
我可以连接,但如果我使用ssh 192.168.1.1
.这是一个小调试
OpenSSH_8.6p1, OpenSSL 1.1.1k 25 Mar 2021
debug1: Reading configuration data /home/user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 192.168.1.1 [192.168.1.1] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 0
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/user/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519_sk type -1
debug1: identity file /home/user/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/user/.ssh/id_xmss type -1
debug1: identity file /home/user/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
debug1: Remote protocol version 2.0, remote software version dropbear
debug1: compat_banner: no match: dropbear
debug1: Authenticating to 192.168.1.1:22 as 'user'
debug1: load_hostkeys: fopen /home/user/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-rsa SHA256:8BU0dCiyV/HSOZyyThViiuLyIQtIyQIQC5d/slYYJts
debug1: load_hostkeys: fopen /home/user/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '192.168.1.1' is known and matches the RSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: (none) RSA SHA256:dGSaK9m1A06YkSEnnLYHt9eHb02JfMeBaKp34SuwPf8 agent
debug1: Will attempt key: /home/user/.ssh/id_rsa RSA SHA256:NUxAd9IHzP1O4GoEUBED1RcPW06JusvfUVIJpLJK754
debug1: Will attempt key: /home/user/.ssh/id_dsa
debug1: Will attempt key: /home/user/.ssh/id_ecdsa
debug1: Will attempt key: /home/user/.ssh/id_ecdsa_sk
debug1: Will attempt key: /home/user/.ssh/id_ed25519
debug1: Will attempt key: /home/user/.ssh/id_ed25519_sk
debug1: Will attempt key: /home/user/.ssh/id_xmss
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: (none) RSA SHA256:dGSaK9m1A06YkSEnnLYHt9eHb02JfMeBaKp34SuwPf8 agent
debug1: Authentications that can continue: publickey
debug1: Offering public key: /home/user/.ssh/id_rsa RSA SHA256:NUxAd9IHzP1O4GoEUBED1RcPW06JusvfUVIJpLJK754
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa_sk
debug1: Trying private key: /home/user/.ssh/id_ed25519
debug1: Trying private key: /home/user/.ssh/id_ed25519_sk
debug1: Trying private key: /home/user/.ssh/id_xmss
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).
在这两种方法都可以使用之前,我该如何解决呢?
答案1
当您使用 时ssh 192.168.1.1
,您将以当前登录的任何用户身份进行连接。作为此用户,您无权访问远程系统,这从日志中可以清楚地看出:
[email protected]: Permission denied (publickey).
要使用 IP 地址,您还应该指定要连接的确切用户:
ssh [email protected]
或者,确保192.168.1.1
您的 SSH 配置中有一个条目:
Host openwrt 192.168.1.1
HostName 192.168.1.1
User root
我编写上述配置条目的方式使两个单独的主机共享同一部分。您还可以在Host
字符串中使用通配符(请参阅man ssh_config
,但这对于解决这个特定问题并不是很有用)。
这将使工作与具有该 SSH 配置的帐户ssh 192.168.1.1
完全相同。ssh openwrt
(作为安全预防措施,我个人不允许在我的任何系统上通过 SSH 进行 root 登录。相反,我会以非特权用户身份登录,然后使用sudo
或某些等效工具来访问特权操作。)