You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Root设备访问tty驱动出现Permission denied错误求助

解决Root设备读取/proc/tty/drivers权限被拒问题
  • 问题核心:/proc是内核虚拟文件系统,直接用chmod修改权限不会生效,因为这些权限由内核动态管理,修改后会被立即重置。

  • 方案1:让应用通过Root权限读取文件
    在应用代码里先请求Root权限,再通过su执行读取命令,示例代码:

    try {
        Process suProcess = Runtime.getRuntime().exec("su");
        OutputStream output = suProcess.getOutputStream();
        output.write("cat /proc/tty/drivers\n".getBytes());
        output.flush();
        output.close();
    
        // 读取输出流获取文件内容
        BufferedReader reader = new BufferedReader(new InputStreamReader(suProcess.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            // 处理读取到的内容
        }
        reader.close();
        suProcess.waitFor();
    } catch (IOException | InterruptedException e) {
        e.printStackTrace();
    }
    
  • 方案2:临时关闭SELinux限制
    部分设备的SELinux Enforcing模式会拦截访问,可通过命令临时关闭:

    su
    setenforce 0
    

    若要永久关闭,编辑/etc/selinux/config文件,把SELINUX=enforcing改成SELINUX=permissive,但这会降低系统安全性,谨慎操作。

  • 方案3:用Magisk模块适配权限(Magisk Root设备)
    如果你用Magisk获取Root,可以安装自定义Magisk模块,添加规则允许目标应用访问/proc/tty/drivers。比如在模块的service.sh里添加:

    chcon u:object_r:proc_tty_drivers:s0 /proc/tty/drivers
    

    或者调整应用的SELinux上下文,让它有权限读取该文件。

内容的提问来源于stack exchange,提问作者Nikhil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 07:01:02