How to run the sftp command with a password from Bash script?

后端 未结 9 585
礼貌的吻别
礼貌的吻别 2020-11-22 11:55

I need to transfer a log file to a remote host using sftp from a Linux host. I have been provided credentials for the same from my operations group. However, since I don\'t

9条回答
  •  隐瞒了意图╮
    2020-11-22 12:25

    Bash program to wait for sftp to ask for a password then send it along:

    #!/bin/bash
    expect -c "
    spawn sftp username@your_host
    expect \"Password\"
    send \"your_password_here\r\"
    interact "
    

    You may need to install expect, change the wording of 'Password' to lowercase 'p' to match what your prompt receives. The problems here is that it exposes your password in plain text in the file as well as in the command history. Which nearly defeats the purpose of having a password in the first place.

提交回复
热议问题