How can I make an expect script prompt for a password?

后端 未结 3 1772
半阙折子戏
半阙折子戏 2020-11-29 04:57

I have an expect script that connects to a few routers through ssh. All these routers have the same password (I know, it\'s wrong), and the script needs to know that passwo

3条回答
  •  醉酒成梦
    2020-11-29 05:28

    Alternatively you could let ssh collect the password via X11 using the SSH_ASKPASS environment variable.

    From the man page:

    > SSH_ASKPASS
    >     If ssh needs a passphrase, it will read the passphrase from the
    >     current terminal if it was run from a terminal.  If ssh does not
    >     have a terminal associated with it but DISPLAY and SSH_ASKPASS
    >     are set, it will execute the program specified by SSH_ASKPASS
    >     and open an X11 window to read the passphrase.  This is particularly
    >     useful when calling ssh from a .xsession or related script.
    >     (Note that on some machines it may be necessary to redirect the
    >     input from /dev/null to make this work.)
    

提交回复
热议问题