远程ssh命令问题

时间:2016-08-10 13:20:07

标签: ssh remotecommand

我在远程计算机上运行命令时遇到一些困难。我无法理解为什么ssh试图认为我传递的命令是主机。

ssh -tt -i /root/.ssh/teamuser.pem teamuser@myserver 'cd ~/bin && ./ssh-out.sh'

|-----------------------------------------------------------------|
| This system is for the use of authorized users only.            |
| Individuals using this computer system without authority, or in |
| excess of their authority, are subject to having all of their   |
| activities on this system monitored and recorded by system      |
| personnel.                                                      |
|                                                                 |
| In the course of monitoring individuals improperly using this   |
| system, or in the course of system maintenance, the activities  |
| of authorized users may also be monitored.                      |
|                                                                 |
| Anyone using this system expressly consents to such monitoring  |
| and is advised that if such monitoring reveals possible         |
| evidence of criminal activity, system personnel may provide the |
| evidence of such monitoring to law enforcement officials.       |
|-----------------------------------------------------------------|

ssh: Could not resolve hostname cd: No address associated with hostname
Connection to myserver closed.

如果我没有传递命令,它绝对正常。它只是让我登录。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

Man ssh说:

  

如果指定了命令,则在远程主机上执行,而不是   登录shell。

问题是cd是内置的bash(在终端中运行type cd)。因此,ssh尝试将cd作为shell运行,但无法在PATH中找到它。

你应该调用ssh这样的东西:

 ssh user@host  -t 'bash -l -c "cd ~/bin && ./ssh-out.sh"'