Ubuntu /etc/rc.local没有运行没有sudo

时间:2015-07-01 07:49:51

标签: ubuntu

我有一个问题,当我添加'ssserver -c /etc/shadowsocks.json -d start'on /etc/rc.local时,它看起来像这样:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

ssserver -c /etc/shadowsocks.json -d start
exit 0

重新启动计算机时无效。 但是当我在“ssserver -c /etc/shadowsocks.json -d start”之前添加sudo时,

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

sudo ssserver -c /etc/shadowsocks.json -d start
exit 0

它非常有效。 那么,这就是为什么?

2 个答案:

答案 0 :(得分:0)

ssserver需要sudo个权限。

ll /etc/shadowsocks.json

  

-rw-r - r-- 1 root root 151 Dec 15 20:40 /etc/shadowsocks.json

答案 1 :(得分:0)

每当使用rc.local时,您都不能认为您的命令是自动识别的,因为在某些情况下尚未加载PATH变量。

尝试运行二进制文件的完整路径,而不仅仅是名称 您可以使用which ssserver

找到二进制文件的完整路径

从我看到的shadowsocks.json文件权限很好,因为所有用户都可以阅读它,如果还需要写入,您可以chmod a+w /etc/shadowsocks.json运行root或使用{ {1}}。