我可以运行位于远程服务器上本地计算机上的bash脚本吗?

问题描述:

我有一些要在远程服务器上运行的本地脚本.我已经设置了ssh密钥对以启用无密码登录.

I have local scripts that I would like to run on a remote server. I have already set up ssh key pairs to enable login without a password.

我当前的方法是将脚本重新同步到服务器,然后运行它:

My current approach is to rsync the script to the server and then run it:

ssh user@remoteserver "rsync localserver:script.sh ./; ./script.sh; rm script.sh"

但是,这似乎是一种破解;有没有更用户友好的方法可以做到这一点?

However, this seems like a hack; Is there a more user friendly way to do this?

更新:既然有很多好的答案,那么有人可以通过提供理由来帮助我选择最佳"答案吗?

update: since there are so many good answers, can anyone help me select the 'best' one by providing rationale?

SSH将接受来自 stdin

ssh -T user@server <script.sh

编辑: -T禁用伪tty分配