Ssh

為什麼我不能使用地址連接到 ssh?

  • August 5, 2021

我已將 gpg-agent 配置為連接到 ssh,但由於某種原因,我無法使用設備地址進行連接。在**~/.ssh/config**我添加了

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.
user@192.168.1.1: Permission denied (publickey).

在此之前我可以使用這兩種方法,我該如何解決?

當您使用ssh 192.168.1.1時,您將以您目前登錄的任何使用者身份連接。作為該使用者,您無權訪問遠端系統,這從日誌中可以清楚地看出:

user@192.168.1.1: Permission denied (publickey).

要使用 IP 地址,您應該另外指定您將連接的確切使用者:

ssh root@192.168.1.1

或者,確保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或其他等效工具來訪問特權操作。)

引用自:https://unix.stackexchange.com/questions/663405