正则表达式模式来编辑/etc/sudoers文件 [英] Regex pattern to edit /etc/sudoers file

查看:113
本文介绍了正则表达式模式来编辑/etc/sudoers文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除/etc/sudoers文件中的(uncommnet#)轮组,所以我应该使用什么Regex模式?

I want to remove (uncommnet #) wheel group in /etc/sudoers file so what would be the Regex pattern i should use?

#cat /etc/sudoers
....
....
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS

## Allows people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL

## Same thing without a password
# %wheel  ALL=(ALL)       NOPASSWD: ALL

....
....

我要从以下行中删除#.

I want to remove # from following line.

...
# %wheel  ALL=(ALL)       NOPASSWD: ALL
...

推荐答案

您不应使用任何类型的脚本来编辑/etc/sudoers文件. visudo命令是有原因的.对sudoers文件的编辑应该很少且控制良好.

You shouldn't edit the /etc/sudoers file with any sort of script. There's a reason for the visudo command. Edits to the sudoers file should be rare and well-controlled.

也就是说,如果visudo命令的编辑器是vi,则可以运行:%s/^# %wheel/%wheel/之类的命令来取消以%wheel开头的所有行的注释.

That being said, if your editor for the visudo command is vi, you can run something like :%s/^# %wheel/%wheel/ to uncomment all of the lines what start with %wheel.

或者,如果您再次觉得有必要:

Or, if you reeeeeeally think it's necessary:

sudo sed --in-place 's/^#\s*\(%wheel\s\+ALL=(ALL)\s\+NOPASSWD:\s\+ALL\)/\1/' /etc/sudoers

先运行而不使用--in-place的命令以检查输出.使用它需要您自担风险.

Run it without the --in-place first to check the output. Use it at your own risk.

这篇关于正则表达式模式来编辑/etc/sudoers文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆