Ubuntu/etc/rc.local 没有 sudo 就无法运行

标签 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

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

最佳答案

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

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

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

关于Ubuntu/etc/rc.local 没有 sudo 就无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31155501/

相关文章:

node.js - npm "failed to parse json"

php - 普拉多和 NetBeans

java - Openfire Smack 连接问题

bash - (学习 Bash)如何从 bash 文件运行多个 postgresql 命令

ubuntu - 使用正则表达式查找两个双引号之间的内容

python - 接收 FileNotFoundError : [Errno 2] No such file or directory

linux - ubuntu 在 ps -ef 命令中不显示用户名

AngularJS + Sailsjs + Nginx = UTC 日期不正确

python - 将两个项目中的公共(public)文件提取到第三个项目中,保留目录结构

c++ - vector<unique_ptr<T>> 在 ubuntu 中占用的内存是 vector<T> 的三倍以上