proper way to sudo over ssh

后端 未结 9 1810
抹茶落季
抹茶落季 2020-11-28 20:33

I have a script which runs another script via SSH on a remote server using sudo. However, when I type the password, it shows up on the terminal. (Otherwise it works fine)

9条回答
  •  醉酒成梦
    2020-11-28 21:24

    I was able to fully automate it with the following command:

    echo pass | ssh -tt user@server "sudo script"
    

    Advantages:

    • no password prompt
    • won't show password in remote machine bash history

    Regarding security: as Kurt said, running this command will show your password on your local bash history, and it's better to save the password in a different file or save the all command in a .sh file and execute it. NOTE: The file need to have the correct permissions so that only the allowed users can access it.

提交回复
热议问题