[英]bash - running remote script from local machine
我試過這個:
#!bin/bash
ssh user@host.com 'sudo /etc/init.d/script restart'
但我得到這個錯誤:
sudo: no tty present and no askpass program specified
我該如何運行該腳本? 現在,當我需要運行該腳本時,我執行以下步驟:
ssh user@host.com
sudo /etc/init.d/script restart
但我不想一直手動登錄到遠程服務器,然后輸入restart命令。
我可以編寫我可以運行的本地腳本,所以我只需要輸入密碼,它會運行遠程腳本並重新啟動進程嗎?
您可以在ssh
命令中使用-t
選項將偽tty附加到 ssh
命令:
ssh -t -t user@host.com 'sudo /etc/init.d/script restart'
按照man ssh
:
-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, eg when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.