What is the cleanest way to ssh and run multiple commands in Bash?

前端 未结 12 2304
礼貌的吻别
礼貌的吻别 2020-11-22 09:14

I already have an ssh agent set up, and I can run commands on an external server in Bash script doing stuff like:

ssh blah_server "ls; pwd;"
         


        
12条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 09:42

    I see two ways:

    First you make a control socket like this:

     ssh -oControlMaster=yes -oControlPath=~/.ssh/ssh-%r-%h-%p 
    

    and run your commands

     ssh -oControlMaster=no -oControlPath=~/.ssh/ssh-%r-%h-%p  -t 
    

    This way you can write an ssh command without actually reconnecting to the server.

    The second would be to dynamically generate the script, scping it and running.

提交回复
热议问题