如何从一个bash脚本中的ssh? [英] How to ssh from within a bash script?

查看:143
本文介绍了如何从一个bash脚本中的ssh?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从脚本中创建一个ssh连接并执行远程服务器上的一些东西。

不过终端提示我输入密码,然后打开终端窗口,而不是脚本的连接。该命令没有得到执行,直到我退出的连接。

如何从一个bash脚本中的ssh?


解决方案

  1. 如果您希望将密码提示消失,那么使用基于密钥验证(的这里描述)。


  2. 要通过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?

解决方案

  1. If you want the password prompt to go away then use key based authentication (described here).

  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆