簡體   English   中英

bash - 從本地計算機運行遠程腳本

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM