Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ubuntu重启&;带密码的关机命令_Ubuntu_Ssh_Sudo_Shutdown_Reboot - Fatal编程技术网

ubuntu重启&;带密码的关机命令

ubuntu重启&;带密码的关机命令,ubuntu,ssh,sudo,shutdown,reboot,Ubuntu,Ssh,Sudo,Shutdown,Reboot,我正在用Java编写一个程序来关闭Ubuntu服务器 echo password | sudo -S shutdown -h now sudo -p 'password' shutdown -h now 两个命令都不起作用 我需要sudo命令关闭并通过传递密码重新启动我的服务器。 因为我是从程序中执行此操作的,所以它不应该提示输入密码。密码也应随命令一起发送。任何建议都会很有帮助。…sudo的-p选项指定提示,而不是密码。看看-a选项。sudo手册页摘录-: -A No

我正在用Java编写一个程序来关闭Ubuntu服务器

 echo password | sudo -S shutdown -h now
 sudo -p 'password' shutdown -h now
两个命令都不起作用

我需要sudo命令关闭并通过传递密码重新启动我的服务器。
因为我是从程序中执行此操作的,所以它不应该提示输入密码。密码也应随命令一起发送。任何建议都会很有帮助。…

sudo的-p选项指定提示,而不是密码。看看-a选项。sudo手册页摘录-:

 -A          Normally, if sudo requires a password, it will read it from the current 
             terminal.  If the -A (askpass) option is specified, a
             helper program is executed to read the user's password and output the 
             password to the standard output.  If the SUDO_ASKPASS environment variable 
             is set, it specifies the path to the helper program.  Otherwise, the value
             specified by the askpass  option in sudoers(5) is used.
助手程序必须输出正确的密码。因此,要指定帮助程序-:

 export SUDO_ASKPASS="/path/to/helper"