Provide password to ssh command inside bash script, Without the usage of public keys and Expect

前端 未结 4 951
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 03:08

I want to use SSH inside a script, but this script is not going to be executed on my machine.

In my implementation there are two limitations.

4条回答
  •  时光取名叫无心
    2021-02-04 03:17

    For security reasons you must avoid providing password on a command line otherwise anyone running ps command can see your password. Better to use sshpass utility like this:

    #!/bin/bash
    
    export SSHPASS="your-password"
    sshpass -e ssh -oBatchMode=no sshUser@remoteHost
    

    You might be interested in How to run the sftp command with a password from Bash script?

提交回复
热议问题