【问题标题】:Need sudo to run erlang escript, even though the file has execute permissions需要 sudo 来运行 erlang escript,即使该文件具有执行权限
【发布时间】:2020-07-25 23:11:16
【问题描述】:

我正在尝试创建一个名为 factorial 的文件,该文件可以使用 erlang 中的 escript 从命令行运行。我实际上是从documentation 复制确切的文件。

我的问题是,即使我做了chmod u+x factorial(以及后来的chmod a+x factorial),我也无法简单地做./factorial 5。我使用ls -l 检查我的文件是否具有正确的权限:

-rwxr-xr-x  1 josh  staff     402 Jul 24 18:43 factorial

只有sudo ./factorial 5才能成功运行文件,这很痛苦,因为我的密码很长,我不想每次都使用sudo。

我不使用 sudo 时遇到的错误如下:

josh@MacBook-Pro test % ./factorial 5
2020-07-24 19:02:53.247288 
    args: []
    format: "Error when reading /Users/josh/.erlang.cookie: eacces"
    label: {error_logger,error_msg}
2020-07-24 19:02:53.247466 supervisor_report   #{label=>{supervisor,start_error},report=>[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{"Error when reading /Users/josh/.erlang.cookie: eacces",[{auth,init_cookie,0,[{file,"auth.erl"},{line,286}]},{auth,init,1,[{file,"auth.erl"},{line,140}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}},{offender,[{pid,undefined},{id,auth},{mfargs,{auth,start_link,[]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}
2020-07-24 19:02:53.247492 crash_report        #{label=>{proc_lib,crash},report=>[[{initial_call,{auth,init,['Argument__1']}},{pid,<0.59.0>},{registered_name,[]},{error_info,{error,"Error when reading /Users/josh/.erlang.cookie: eacces",[{auth,init_cookie,0,[{file,"auth.erl"},{line,286}]},{auth,init,1,[{file,"auth.erl"},{line,140}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}},{ancestors,[net_sup,kernel_sup,<0.47.0>]},{message_queue_len,0},{messages,[]},{links,[<0.57.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,987},{stack_size,27},{reductions,894}],[]]}
2020-07-24 19:02:53.247955 supervisor_report   #{label=>{supervisor,start_error},report=>[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,{shutdown,{failed_to_start_child,auth,{"Error when reading /Users/josh/.erlang.cookie: eacces",[{auth,init_cookie,0,[{file,"auth.erl"},{line,286}]},{auth,init,1,[{file,"auth.erl"},{line,140}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}}}},{offender,[{pid,undefined},{id,net_sup},{mfargs,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}
2020-07-24 19:02:53.249031 crash_report        #{label=>{proc_lib,crash},report=>[[{initial_call,{application_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,<0.46.0>},{registered_name,[]},{error_info,{exit,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{"Error when reading /Users/josh/.erlang.cookie: eacces",[{auth,init_cookie,0,[{file,"auth.erl"},{line,286}]},{auth,init,1,[{file,"auth.erl"},{line,140}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}},[{application_master,init,4,[{file,"application_master.erl"},{line,138}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}},{ancestors,[<0.45.0>]},{message_queue_len,1},{messages,[{'EXIT',<0.47.0>,normal}]},{links,[<0.45.0>,<0.44.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,987},{stack_size,27},{reductions,184}],[]]}
2020-07-24 19:02:53.249780 std_info            #{label=>{application_controller,exit},report=>[{application,kernel},{exited,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{"Error when reading /Users/josh/.erlang.cookie: eacces",[{auth,init_cookie,0,[{file,"auth.erl"},{line,286}]},{auth,init,1,[{file,"auth.erl"},{line,140}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}}},{type,permanent}]}
{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{\"Error when reading /Users/josh/.erlang.cookie: eacces\",[{auth,init_cookie,0,[{file,\"auth.erl\"},{line,286}]},{auth,init,1,[{file,\"auth.erl\"},{line,140}]},{gen_server,init_it,2,[{file,\"gen_server.erl\"},{line,374}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,249}]}]}}}}},{kernel,start,[normal,[]]}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_child,net_sup,{shutdown,{failed_to_start_child,auth,{"Error when reading /Users/josh/.erla

Crash dump is being written to: erl_crash.dump...done


一开始我以为问题可能出在/Users/josh/.erlang.cookie 文件的权限上,但是更改该文件的权限会导致错误,因为显然只有所有者才能拥有该文件的读取权限。

那么,我需要做什么才能使用./factorial 5 运行文件而不必使用sudo ./factorial 5

【问题讨论】:

  • 尝试删除.erlang.cookie,然后执行脚本sudo rm /Users/josh/.erlang.cookie,然后再执行./factorial 5
  • StackOverflow 致力于帮助解决编程代码问题。您的 Q 可能更适合 Super UserUnix & Linux,但请阅读他们关于主题问题的帮助部分。并且请先阅读Help On-topicHelp How-to-ask,然后再在此处发布更多问题。祝你好运。

标签: shell unix erlang


【解决方案1】:

看起来/Users/josh/.erlang.cookie 归根用户所有,而不是您自己的用户。您可以删除它(它将自动重新创建),或更改所有者:

sudo chown josh /Users/josh/.erlang.cookie

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 2014-06-17
    • 2013-02-19
    • 2015-09-24
    • 2019-06-15
    • 1970-01-01
    • 2012-07-28
    相关资源
    最近更新 更多