0

我有一个命令想用 ssh 连接远程服务器。我的命令是

"ssh -o PasswordAuthentication=no $REMOTE_HOST_IP > /dev/null 2>&1"

当这有效时,真正的消息来了“权限被拒绝”。这是真正的消息,但我不想在控制台上看到消息,所以我将它重定向到 /dev/null。但仍然出现。问题是什么

编辑:我按照你说的尝试过,在 /dev/null 之前取了 2&1 但它仍然不起作用。但奇怪的是它可以在我朋友的电脑上运行

已解决:问题是我将命令分配给一个变量并将其作为 $command 运行。但是当它设置在“”之间时,重定向不起作用

4

4 回答 4

2

-n选项

-n      Redirects stdin from /dev/null (actually, prevents reading from
         stdin).  This must be used when ssh is run in the background.  A
         common trick is to use this to run X11 programs on a remote
         machine.  For example, ssh -n shadows.cs.hut.fi emacs & will
         start an emacs on shadows.cs.hut.fi, and the X11 connection will
         be automatically forwarded over an encrypted channel.  The ssh
         program will be put in the background.  (This does not work if
         ssh needs to ask for a password or passphrase; see also the -f
         option.)

甚至在-N

 -N      Do not execute a remote command.  This is useful for just for‐
         warding ports (protocol version 2 only).
于 2012-08-13T13:29:20.963 回答
1

尝试

ssh -o PasswordAuthentication=no $REMOTE_HOST_IP &>/dev/null
于 2012-08-13T13:28:52.147 回答
0

试试这个(在将2>&1重定向标准错误发送到 /dev/null 之前移动它):

 "ssh -o PasswordAuthentication=no $REMOTE_HOST_IP 2>&1 > /dev/null"

请注意,您正在使用2>&1. 如果您只想将 stderr 重定向到 /dev/null ,那么只需使用2> /dev/null.

关于IO 重定向的好信息在这里。

于 2012-08-13T13:25:44.850 回答
0

ssh -o PasswordAuthentication=no $REMOTE_HOST_IP 2> /dev/null

于 2012-08-13T13:27:37.037 回答