Bash
通過 SSH 連接時出現語法錯誤
當使用我的 openSUSE 15.1 機器通過 ssh 連接到一些 linux 伺服器時,我得到了奇怪的 EOF 和語法錯誤。我幾乎執行了一個標准設置,除了啟用 pubkey 身份驗證之外沒有更改任何內容。
這就是發生的事情:
~> ssh randomserver.hostname bash: -c: line 0: unexpected EOF while looking for matching `"' bash: -c: line 1: syntax error: unexpected end of file Connection to randomserver.hostname closed.
在斷開連接之前,錯誤是在我的本地電腦上生成還是源自遠端伺服器?
的輸出
ssh -v
是:~> ssh -v randomserver.hostname OpenSSH_7.9p1, OpenSSL 1.1.0i-fips 14 Aug 2018 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 20: Applying options for * debug1: Connecting to randomserver.hostname [192.168.1.2] port 22. debug1: Connection established. debug1: identity file /home/myuser/.ssh/id_rsa type 0 debug1: identity file /home/myuser/.ssh/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.4p1 Debian-10+deb9u7 debug1: match: OpenSSH_7.4p1 Debian-10+deb9u7 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 randomserver.hostname:22 as 'root' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 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: kex: curve25519-sha256 need=64 dh_need=64 debug1: kex: curve25519-sha256 need=64 dh_need=64 debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx debug1: Host 'randomserver.hostname' is known and matches the ECDSA host key. debug1: Found key in /home/myuser/.ssh/known_hosts debug1: rekey after 134572247 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey after 134572548 blocks debug1: Will attempt key: /home/myuser/.ssh/id_rsa XXXX debug1: SSH2_MSG_EXT_INFO received debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521> debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,password debug1: Next authentication method: publickey debug1: Offering public key: /home/myuser/.ssh/id_rsa XXXX debug1: Server accepts key: /home/myuser/.ssh/id_rsa XXXX debug1: Authentication succeeded (publickey). Authenticated to randomserver.hostname ([192.168.1.2]:22). debug1: channel 0: new [client-session] debug1: Requesting no-more-sessions@openssh.com debug1: Entering interactive session. debug1: pledge: network debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0 debug1: Remote: Forced command. debug1: Remote: Forced command. debug1: Requesting authentication agent forwarding. debug1: Sending environment. debug1: Sending env LANG = de_DE.utf8 debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0 bash: -c: line 0: unexpected EOF while looking for matching `"' bash: -c: line 1: syntax error: unexpected end of file debug1: channel 0: free: client-session, nchannels 1 Connection to randomserver.hostname closed. Transferred: sent 3864, received 3020 bytes, in 0.1 seconds Bytes per second: sent 75479.5, received 58992.8 debug1: Exit status 1
在不更改所有遠端配置的情況下,我可以做些什麼來解決這個問題?
在該
.ssh/authorized_keys
文件中,您可以強制在登錄之前執行命令。可以在那裡找到語法錯誤(使用command=""
)。這已用於使用唯一密鑰標識符(除了 IP 地址和主機名)將任何管理員的登錄記錄到系統日誌中。
好像登錄後,
bash
正在嘗試為您自動執行命令。嘗試使用如下顯式命令登錄:
$ ssh -t randomserver.hostname "bash --norc --noprofile"
如果可行,那麼在給你一個 shell 之前檢查 bash 載入的文件,搜尋任何不尋常的行或語法錯誤。