庆典 - 从运行本地计算机远程脚本 [英] bash - running remote script from local machine

查看:113
本文介绍了庆典 - 从运行本地计算机远程脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这样:

#!bin/bash
ssh user@host.com  'sudo /etc/init.d/script restart'

但我得到这个错误:

But I get this error:

sudo: no tty present and no askpass program specified

我怎样才能运行该脚本?现在,当我需要运行该脚本我做这些步骤:

How can I run that script? Now when I need to run that script I do these steps:

ssh user@host.com
sudo /etc/init.d/script restart

但我并不想手动登录到远程服务器上所有的时间,然后输入重启命令。

But I don't want to manually log in to remote server all the time and then enter restart command.

我可以写,我可以运行,因此当地的剧本我只需要输入密码,它会运行远程脚本并重新启动进程?

Can I write local script that I could run so I would only need to enter password and it would run remote script and restart the process?

推荐答案

您可以使用 -t 选项 SSH 命令的连接伪终端 SSH 命令:

You can use -t option in ssh command to attach a pseudo-tty with your ssh command:

ssh -t -t user@host.com 'sudo /etc/init.d/script restart'

男人SSH

-t部队伪终端分配。这可用于在远程机器,它可以是非常有用的,例如在执行任意基于屏幕的节目执行菜单服务时。多个-t选项力tty分配,即使SSH有没有本地的tty。

这篇关于庆典 - 从运行本地计算机远程脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆