How to ssh from within a bash script?

前端 未结 4 885
温柔的废话
温柔的废话 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条回答
  •  日久生厌
    2020-12-07 13:48

    If you want to continue to use passwords and not use key exchange then you can accomplish this with 'expect' like so:

    #!/usr/bin/expect -f
    spawn ssh user@hostname
    expect "password:"
    sleep 1
    send "\r"
    command1
    command2
    commandN
    

提交回复
热议问题