bash 没有欢迎横幅的 ssh 登录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22891708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ssh login without welcome banner
提问by Marian
I am using ssh from a program which sends commands to ssh and parses answers. However, each time I log in, I get the welcome banner like:
我正在使用一个程序中的 ssh,该程序将命令发送到 ssh 并解析答案。但是,每次登录时,我都会收到如下欢迎横幅:
Linux mymachine 3.2.0-4-686-pae #1 SMP Debian 3.2.54-2 i686
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
...
I do not want this banner, because my parser would need to deal with it. Is it possible to login with ssh and not to get this banner at the beginning?
我不想要这个横幅,因为我的解析器需要处理它。是否可以使用 ssh 登录而不是在开始时获得此横幅?
采纳答案by Keith Reynolds
This will run command1 command2 and command3 on the remote_host.
这将在 remote_host 上运行 command1 command2 和 command3。
ssh user@remote_host 'command1; command2; command3'
No banners are displayed.
不显示横幅。
回答by PfMoriarty7
You should be able to silence this banner, and other diagnostic messages, by passing -q
to SSH:
您应该能够通过传递-q
给 SSH来使此横幅和其他诊断消息静音:
ssh -q user@remote_host
If you want to make -q
permanent for all your SSH sessions, do:
如果您想-q
永久保留所有 SSH 会话,请执行以下操作:
echo "LogLevel QUIET" >> ~/.ssh/config
回答by Anirvan
Try ssh -q to supress the banner message
尝试 ssh -q 来抑制横幅消息
回答by foz
What works here seems to depend on the operating system, SSH version, and the server-side configuration of sshd
.
这里的工作似乎取决于操作系统、SSH 版本和sshd
.
For connecting to a stock Ubuntu 18 server ssh -q
didn't work for me, and neither did ssh -o LogLevel=error
that is suggested elsewhere.
对于连接到股票 Ubuntu 18 服务器ssh -q
对我来说不起作用,ssh -o LogLevel=error
其他地方也没有建议这样做。
What did work is the comment posted under the question about creating a .hushlogin
file in the remote user's home directory:
有效的是在关于.hushlogin
在远程用户的主目录中创建文件的问题下发布的评论:
$ ssh myuser@myhost
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-55-generic x86_64)
<snip>
Last login: Thu Aug 1 14:04:26 2019 from 1.2.3.4
myuser@myhost$ touch .hushlogin
myuser@myhost$ exit
Then:
然后:
$ ssh myuser@myhost echo 'Test'
Test
回答by Marian
I answer my own question with the solution based on Keith Reynolds answer. I am using:
我使用基于 Keith Reynolds 答案的解决方案来回答我自己的问题。我在用:
ssh my_host bash
allowing bash interaction without banner and without prompt.
允许在没有横幅和提示的情况下进行 bash 交互。
回答by MLSC
For running commands remotely:
远程运行命令:
#!/bin/bash
SCRIPT='
#Your commands
'
sshpass -p<pass> ssh -o 'StrictHostKeyChecking no' -p <port> user@host "$SCRIPT"