0

尝试通过 ssh 执行命令,但我没有收到任何回复。服务器 A 是 Solaris 机器,服务器 B 是带有 OpenBSD sshd 的 SUSE linux。已检查

  1. ssh 远程命令不返回
  2. https://www.openbsd.org/papers/auug2002-ssh.pdf
  3. https://superuser.com/questions/792070/commands-over-ssh-not-production-output

和其他来源,但无法解决。

我正在尝试的命令是(在 bash 中):

    ssh -v -i .ssh/id_rsa -p1234 user2@abcdefg 'ls'

(尝试不带引号和双引号)

我收到的调试信息是:

    Sun_SSH_1.1.6, SSH protocols 1.5/2.0, OpenSSL 0x0090704f
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: Rhosts Authentication disabled, originating port will not be trusted.
    debug1: ssh_connect: needpriv 0
    debug1: Connecting to ABCDEFG [100.100.100.100] port 1234.
    debug1: Connection established.
    debug1: identity file ../../../.ssh/id_rsa type 1
    debug1: Logging to host: abcdefg
    debug1: Local user: user1 Remote user: user2
    debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
    debug1: match: OpenSSH_6.2 pat OpenSSH*
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-Sun_SSH_1.1.6
    debug1: use_engine is 'yes'
    debug1: pkcs11 engine initialized, now setting it as default for RSA, DSA, and symmetric ciphers
    debug1: pkcs11 engine initialization complete
    debug1: Failed to acquire GSS-API credentials for any mechanisms (No credentials were supplied, or the credentials were unavailable or inaccessible
Unknown code 0
)
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: server->client aes128-ctr hmac-md5 none
    debug1: kex: client->server aes128-ctr hmac-md5 none
    debug1: Peer sent proposed langtags, ctos:
    debug1: Peer sent proposed langtags, stoc:
    debug1: We proposed langtags, ctos: i-default
    debug1: We proposed langtags, stoc: i-default
    debug1: SSH2_MSG_KEX_DH_GEX_REQUEST sent
    debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
    debug1: dh_gen_key: priv key bits set: 128/256
    debug1: bits set: 1014/2048
    debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
    debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
    debug1: Host 'abcdefg' is known and matches the RSA host key.
    debug1: Found key in /home/user1/.ssh/known_hosts:1
    debug1: bits set: 1019/2048
    debug1: ssh_rsa_verify: signature correct
    debug1: newkeys: mode 1
    debug1: set_newkeys: setting new keys for 'out' mode
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: newkeys: mode 0
    debug1: set_newkeys: setting new keys for 'in' mode
    debug1: SSH2_MSG_NEWKEYS received
    debug1: done: ssh_kex2.
    debug1: send SSH2_MSG_SERVICE_REQUEST
    debug1: got SSH2_MSG_SERVICE_ACCEPT
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: publickey
    debug1: Trying public key: .ssh/id_rsa
    debug1: Server accepts key: pkalg ssh-rsa blen 149 lastkey 80b0320 hint 0
    debug1: read PEM private key done: type RSA
    debug1: Authentication succeeded (publickey)
    debug1: SSH receive window size: 198720 B
    debug1: channel 0: new [client-session]
    debug1: send channel open 0
    debug1: Entering interactive session.
    debug1: ssh_session2_setup: id 0
    debug1: Sending command: ls
    debug1: channel request 0: exec
    debug1: channel 0: open confirm rwindow 0 rmax 32768
    debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
    debug1: channel 0: rcvd eof
    debug1: channel 0: output open -> drain
    debug1: channel 0: obuf empty
    debug1: channel 0: close_write
    debug1: channel 0: output drain -> closed
    debug1: channel 0: rcvd close
    debug1: channel 0: close_read
    debug1: channel 0: input open -> closed
    debug1: channel 0: almost dead
    debug1: channel 0: gc: notify user
    debug1: channel 0: gc: user detached
    debug1: channel 0: send close
    debug1: channel 0: is dead
    debug1: channel 0: garbage collecting
    debug1: channel_free: channel 0: client-session, nchannels 1
    debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.1 seconds
    debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
    debug1: Exit status 1

serverB 上的 ssh_config 文件如下所示:

#       $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# Configuration file set-up to meet APG43L needs.

Protocol 2
PasswordAuthentication yes
UsePAM yes
################################################################################
# Access to sftp subsystem is DISABLED                                         #
# Subsystem sftp internal-sftp                                                 #
################################################################################
PermitRootLogin no
Ciphers aes128-ctr,aes256-ctr,arcfour256,arcfour,aes128-cbc,aes256-cbc
PrintLastLog no
Port 1234


# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys

AuthorizedKeysFile      .ssh/authorized_keys

AllowGroups group1 group2 group3
AllowUsers user2
RSAAuthentication yes
PubkeyAuthentication yes4

编辑:我试图在远程机器上执行命令并将其输出重定向到远程文件,但这也不起作用。没有创建文件(如果我在远程服务器上,我可以在目录中写入该文件)。我也调整了这个问题。

ssh -v -i .ssh/id_rsa -p1234 user2@abcdefg 'ls > output.dat'
4

1 回答 1

0

奇怪,当然不是你的命令——类似于单引号对我有用。我得到相同的调试输出到“debug1:发送命令:ls”)所以一切都很好,但你只是没有得到我得到的输出!

一些谷歌搜索意味着命令的这种变化会得到结果

echo 'ls' | ssh -v -i .ssh/id_rsa -p1234 user2@abcdefg

https://superuser.com/questions/792070/commands-over-ssh-not-production-output

我假设您对您的主目录具有可执行权限(如果您没有,会感到惊讶)......但是假设是所有问题的根源,所以请检查您实际上是否可以在实际客户端上运行。

于 2016-09-29T22:40:49.453 回答