如何从一个bash脚本中的ssh? [英] How to ssh from within a bash script?
问题描述
我想从脚本中创建一个ssh连接并执行远程服务器上的一些东西。
不过终端提示我输入密码,然后打开终端窗口,而不是脚本的连接。该命令没有得到执行,直到我退出的连接。
我如何从一个bash脚本中的ssh?
-
如果您希望将密码提示消失,那么使用基于密钥验证(的这里描述)。
-
要通过SSH远程运行命令,你必须给他们作为一个参数为SSH,如下所示:
根@主持人:〜#SSH根@ WWWPS -ef | grep的阿帕奇| grep的-v grep的|厕所-l
块引用>I am trying to create an ssh connection and do some things on the remote server from within the script.
However the terminal prompts me for a password, then opens the connection in the terminal window instead of the script. The commands don't get executed until I exit the connection.
How can I ssh from within a bash script?
解决方案
If you want the password prompt to go away then use key based authentication (described here).
To run commands remotely over ssh you have to give them as an argument to ssh, like the following:
root@host:~ # ssh root@www 'ps -ef | grep apache | grep -v grep | wc -l'
这篇关于如何从一个bash脚本中的ssh?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!