How to ssh from within a bash script?

前端 未结 4 883
温柔的废话
温柔的废话 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条回答
  •  Happy的楠姐
    2020-12-07 13:42

    There's yet another way to do it using Shared Connections, ie: somebody initiates the connection, using a password, and every subsequent connection will multiplex over the same channel, negating the need for re-authentication. ( And its faster too )

    # ~/.ssh/config 
    ControlMaster auto
    ControlPath ~/.ssh/pool/%r@%h
    

    then you just have to log in, and as long as you are logged in, the bash script will be able to open ssh connections.

    You can then stop your script from working when somebody has not already opened the channel by:

    ssh ... -o KbdInteractiveAuthentication=no ....
    

提交回复
热议问题