为什么我不能在远程主机上执行 SSH 命令?

fir*_*ank 7 ssh ssh-tunneling

我正在通过 jumpbox 访问远程主机。如果我通过 ssh shell 访问远程主机,我可以轻松访问它:

ssh remoteHost

Last login: Tue Feb 16 12:56:26 2016 from xx.xxx.xx.xx

remoteHost:user:~$ ls

<shows all the stuff>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试通过 SSH 命令行选项执行命令时,我总是得到:

ssh remoteHost ls

"ls" isn't allowed to be executed.

Killed by signal 1.
Run Code Online (Sandbox Code Playgroud)

我可以在某些主机上成功执行 ssh 命令,但不能在其他主机上成功执行。

这是一个可以在服务器上配置的设置,即“允许远程 ssh 命令”或类似的东西吗?

FWIW,我确实看过如何在没有密码的情况下使用 ssh 在远程主机上启用使用命令?,但我很确定我的问题与引用无关,因为该问题的唯一答案似乎表明。

更新:

在远程主机上,我有一个 authorized_keys2 文件,其中包含如下内容:

ssh-rsa <encrypted stuff> jumpbox_user@jumpbox
ssh-rsa <encrypted stuff> jumpbox_user@mydesktop
Run Code Online (Sandbox Code Playgroud)

我的 ssh/.config 文件如下所示:

Host remoteHost
  HostName remoteHost
  User user
  ProxyCommand ssh -W %h:%p jumpbox_user@jumpbox_host
  ServerAliveInterval 60
Run Code Online (Sandbox Code Playgroud)

Nas*_*rka 1

尝试使用该选项运行您的 ssh 线路-t,并确保您的远程命令由 \' 分隔,因为这告诉 ssh 在远程主机上运行该命令,从而使您的线路更加防错。

\n
ssh user@remoteHost -t \'ls\'\n
Run Code Online (Sandbox Code Playgroud)\n

仅供参考: -t 选项启用伪终端分配,它实际上模拟打开 SSH 终端,然后键入命令,然后输出 STDOUT 并退出 - 这正是您提到的手动执行的操作。

\n

根据 SSH 手册页:

\n
\n

-t 强制伪终端分配。这可用于在远程计算机上执行\xe2\x80\x90\ncute任意基于屏幕的程序,\n这非常有用,例如在实现菜单服务\xe2\x80\x90\nvices时。多个 -t 选项强制 tty 分配,即使\nssh 没有本地 tty。

\n
\n

参考:

\n

SSH 手册页

\n

什么是伪 TTY 分配?

\n