当使用我的 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: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] 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 [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] 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 [email protected] 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
在不更改所有远程配置的情况下,我可以做什么来解决此问题?
答案1
在该.ssh/authorized_keys
文件中,您可以在登录之前强制运行命令。可以在其中找到语法错误(使用command=""
)。
这已用于使用唯一的密钥标识符(除了 IP 地址和主机名)将任何管理员的登录记录到系统日志中。
答案2
似乎登录后,bash
正在尝试自动为您运行命令。
尝试使用显式命令登录,如下所示:
$ ssh -t randomserver.hostname "bash --norc --noprofile"
如果可行,请在提供 shell 之前检查 bash 加载的文件,搜索任何不寻常的行或语法错误。