惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
V
V2EX
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
小众软件
小众软件
Vercel News
Vercel News
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
J
Java Code Geeks
P
Proofpoint News Feed
MongoDB | Blog
MongoDB | Blog
B
Blog
美团技术团队
量子位

Allen Hua 的网络博客

由于 Linux 桌面没有一个好用的天气程序就写了一个跨平台的CheckitoutWeather 给 caesium-image-compressor 图片压缩程序构建了 Linux AppImage v2.8.5 最新版 debian13(debian trixie)安装了nvidia闭源驱动后从x11切换到wayland的方法 山间摩旅追风,偶遇一场绚烂晚霞 最近使用debian系统的一些心得 机械革命无界14Pro笔记本debian forky成功驱动内置扬声器和麦克风 记录 typecho 1.2.0 升级到 1.3.0 过程 开发了一款openwrt插件:文本剪贴板 解决机械革命笔记本内屏高刷240Hz闪屏问题 使用 Java 写了一个局域网端口扫描器 - Allen Hua 的网络博客 openwrt使用外置根extroot机制扩展根分区大小 - Allen Hua 的网络博客 将机场ss节点批量转换成ss字符串链接批量添加到passwall - Allen Hua 的网络博客 给机械革命钛钽plus换屏:NY2换成NZ2 - Allen Hua 的网络博客 记录一次pve宿主机和上面的debian虚机无故down机事件 - Allen Hua 的网络博客 给图床部署cdn腾讯云的edgeone并排查Cache-Control max-age 3600的问题 - Allen Hua 的网络博客 从高山草甸到徽派古村:武功山反穿与皖浙赣自驾行记 - Allen Hua 的网络博客 增程器就是充电宝?别被忽悠了 - Allen Hua 的网络博客 浦口龙虎巷扫街,记录人间真实 博客图片压缩方案更新|AVIF|WebP|MozJPEG|标准JPEG Windows 电脑使用 Obs Studio 录制各个网站视频/桌面画面教程 为typecho博客添加latex支持 新能源汽车之纯电车使用交流慢充和直流快充的充电损耗对比 2025年3月更新全国5A景区名录 2025最新查看小米/红米手机电池健康度和循环次数方法 完美解决 seafile FILE_SERVER_ROOT 配置导致的内网外网不能同时访问和上传下载的问题 纯css实现typecho博客文章文字spoiler剧透效果 我对Typecho Facile主题的一些修改,图片懒加载优化,样式定制 2024年8月我的宜昌 - 重庆 - 川西小环线自驾旅行分享 2022年打卡南京市区人防工程纳凉点 2024年带着A7C2+腾龙28-200 再次来到红山森林动物园
OpenWrt 普通用户无法使用 sudo 提权,报错 Error relocating...
Allen Hua · 2022-03-13 · via Allen Hua 的网络博客
阅读量:4860

warning: 这篇文章距离上次修改已过1529天,其中的内容可能已经有所变动。

使用普通用户登录,执行 sudo mkdir test 报错,错误信息如下

$ sudo mkdir test
Error relocating /usr/lib/sudo/libsudo_util.so.0: reallocarray: symbol not found
Error relocating /usr/bin/sudo: reallocarray: symbol not found

经过一番搜寻,只找到了这个帖子 [openwrt(x86)] 请教一下关于openwrt安装xteve遇到不让用root用户运行的问题 ,但这个帖子并没有解决办法(你现在看到的此帖中的解决办法就是我给出的)

在 superuser.com superuser.forumming.com askubuntu.com 等等网站上也找到了一些信息,但是和 OpenWrt 相关性不大,并不能解决我的问题。

在 pkgs.org 搜到了下面这个包 https://openwrt.pkgs.org/19.07/openwrt-packages-x86_64/sudo_1.8.28p1-2_x86_64.ipk.html 经过一番版本比对,我决定安装这个试试。

我现在使用的 opkg 源是中科大 ustc 的,其版本号比这个要高。

下面是我的解决办法。

1. 移除旧版本 sudo

首先将 /etc/sudoers 文件恢复原样,删除 root ALL=(ALL:ALL) ALL 下面的一行 dk ALL=(ALL:ALL) ALL,之所以删除是因为有修改直接删除会报错(我记得是这样,如果你直接 remove 不报错那就没关系这一步是多余的)

查看当前版本的 sudo 程序信息

# opkg info sudo
Package: sudo
Version: 1.8.28p1-1
Depends: libc
Status: unknown ok not-installed
Section: admin
Architecture: x86_64
Size: 309411
Filename: sudo_1.8.28p1-1_x86_64.ipk
Description: Sudo (su "do") allows a system administrator to delegate authority to
give certain users (or groups of users) the ability to run some (or
all) commands as root or another user while providing an audit trail of
the commands and their arguments.

Package: sudo
Version: 1.9.9-1
Depends: libc
Status: install user installed
Section: admin
Architecture: x86_64
Size: 447454
Filename: sudo_1.9.9-1_x86_64.ipk
Conffiles:
/etc/sudoers f9a9eb21cc7cccec67bfe982b1268dacea831946ad64863921029212e588f9c8
Description: Sudo (su "do") allows a system administrator to delegate authority to
give certain users (or groups of users) the ability to run some (or
all) commands as root or another user while providing an audit trail of
the commands and their arguments.
Installed-Time: 1647132149

以上时间戳 1647132149 转换后时间是 2022-03-13 08:42:29 是我今天早上通过 opkg remove sudo && opkg install sudo 重新安装的

然后执行 opkg remove sudo 正常卸载。

2. 下载 sudo_1.8.28p1-2_x86_64.ipk 并安装

# wget https://downloads.openwrt.org/releases/packages-19.07/x86_64/packages/sudo_1.8.28p1-2_x86_64.ipk
# opkg install sudo_1.8.28p1-2_x86_64.ipk

3. 编辑 /etc/sudoers 文件

临时授予写权限,文件编辑好之后删除写权限

# chmod u+w /etc/sudoers

然后在 root ALL=(ALL) ALL 下新增 dk ALL=(ALL) ALL,再执行 chmod u-w /etc/sudoers 删除写权限。

再次测试普通用户已经可以通过 sudo 获得临时提权了。sudo mkdir test 执行成功。

$ sudo mkdir test

记录一下新安装的 sudo 程序的信息

# opkg info sudo
Package: sudo
Version: 1.8.28p1-1
Depends: libc
Status: unknown ok not-installed
Section: admin
Architecture: x86_64
Size: 309411
Filename: sudo_1.8.28p1-1_x86_64.ipk
Description: Sudo (su "do") allows a system administrator to delegate authority to
 give certain users (or groups of users) the ability to run some (or
 all) commands as root or another user while providing an audit trail of
 the commands and their arguments.

Package: sudo
Version: 1.9.9-1
Depends: libc
Status: unknown ok not-installed
Section: admin
Architecture: x86_64
Size: 447454
Filename: sudo_1.9.9-1_x86_64.ipk
Description: Sudo (su "do") allows a system administrator to delegate authority to
 give certain users (or groups of users) the ability to run some (or
 all) commands as root or another user while providing an audit trail of
 the commands and their arguments.

Package: sudo
Version: 1.8.28p1-2
Depends: libc
Status: install user installed
Architecture: x86_64
Conffiles:
 /etc/sudoers 67797f145f3429db6e72b4f1b20a13abd0a5c152557a16eff697d05d6a16795e
Installed-Time: 1647168483

这个时间戳 1647168483 转换后时间是 2022-03-13 18:48:03

4. 其他补充信息

当前 openwrt 发行版本信息

$ cat /etc/openwrt_release 
DISTRIB_ID='OpenWrt'
DISTRIB_RELEASE='SNAPSHOT'
DISTRIB_TARGET='x86/64'
DISTRIB_ARCH='x86_64'
DISTRIB_TAINTS='no-all override'
DISTRIB_REVISION='R20.3.19 / Mask Ver.D200401'
DISTRIB_DESCRIPTION='OpenWrt '

一开始安装的 sudo 程序的 /etc/sudoers 文件的 root 提权部分是这样的

##
## User privilege specification
##
root ALL=(ALL:ALL) ALL
dk ALL=(ALL:ALL) ALL

后安装的 sudo 程序(是我目前正常工作的 sudo 程序)的 /etc/sudoers 文件 root 提权部分是这样的。这两个有什么区别呢?感兴趣可以 google 搜索一下(实际上我也不知道,我也要学习一下)

##
## User privilege specification
##
root ALL=(ALL) ALL
dk ALL=(ALL) ALL

特此记录。有问题欢迎友好讨论。