How to ssh from within a bash script?

前端 未结 4 888
温柔的废话
温柔的废话 2020-12-07 13:35

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 th

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 13:44

    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'

提交回复
热议问题