sudoers不知哪里错了

最大的社区版本,Ubuntu的发源地
回复
yangdawei.hit
帖子: 245
注册时间: 2015-01-02 15:32
系统: Debian

sudoers不知哪里错了

#1

帖子 yangdawei.hit » 2016-02-28 7:41

sudoers不知怎么改错了,请教问题出在哪里。

代码: 全选

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
yangdawei ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

代码: 全选

>>> /etc/sudoers: syntax error near line 9 <<<
>>> /etc/sudoers: syntax error near line 9 <<<
>>> /etc/sudoers: syntax error near line 9 <<<
>>> /etc/sudoers: syntax error near line 9 <<<
>>> /etc/sudoers: syntax error near line 10 <<<
>>> /etc/sudoers: syntax error near line 11 <<<
>>> /etc/sudoers: syntax error near line 12 <<<
>>> /etc/sudoers: syntax error near line 13 <<<
>>> /etc/sudoers: syntax error near line 14 <<<
>>> /etc/sudoers: syntax error near line 16 <<<
>>> /etc/sudoers: syntax error near line 18 <<<
>>> /etc/sudoers: syntax error near line 18 <<<
>>> /etc/sudoers: syntax error near line 18 <<<
parse error in /etc/sudoers near line 9
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: sudoers不知哪里错了

#2

帖子 poloshiao » 2016-02-28 10:02

sudoers不知怎么改错了
請把你修改的完整指令 貼上來
yangdawei.hit
帖子: 245
注册时间: 2015-01-02 15:32
系统: Debian

Re: sudoers不知哪里错了

#3

帖子 yangdawei.hit » 2016-02-28 10:17

請把你修改的完整指令 貼上來
sudoers的完整内容是:

代码: 全选

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

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

# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
然后更新:
source sudoers
报错信息:

代码: 全选

bash: Defaults: command not found
bash: Defaults: command not found
bash: $'\r': command not found
bash: $'\r': command not found
bash: $'\r': command not found
bash: $'\r': command not found
bash: sudoers: line 19: syntax error near unexpected token `('
'ash: sudoers: line 19: `root	ALL=(ALL:ALL) ALL
检查语法:
visudo -c

代码: 全选

>>> /etc/sudoers: syntax error near line 9 <<<
>>> /etc/sudoers: syntax error near line 9 <<<
>>> /etc/sudoers: syntax error near line 9 <<<
>>> /etc/sudoers: syntax error near line 10 <<<
>>> /etc/sudoers: syntax error near line 11 <<<
>>> /etc/sudoers: syntax error near line 12 <<<
>>> /etc/sudoers: syntax error near line 13 <<<
>>> /etc/sudoers: syntax error near line 14 <<<
>>> /etc/sudoers: syntax error near line 15 <<<
>>> /etc/sudoers: syntax error near line 16 <<<
>>> /etc/sudoers: syntax error near line 17 <<<
>>> /etc/sudoers: syntax error near line 18 <<<
>>> /etc/sudoers: syntax error near line 18 <<<
>>> /etc/sudoers: syntax error near line 18 <<<
parse error in /etc/sudoers near line 9
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: sudoers不知哪里错了

#4

帖子 poloshiao » 2016-02-28 10:21

請把你修改的完整指令 貼上來
1. 你使用什麼方法或指令修改 sudoers ?
請貼上來完整指令

2. 你修改 sudoers 期望達到麼目的 ?
yangdawei.hit
帖子: 245
注册时间: 2015-01-02 15:32
系统: Debian

Re: sudoers不知哪里错了

#5

帖子 yangdawei.hit » 2016-02-28 11:31

代码: 全选

 	
引用:
請把你修改的完整指令 貼上來

1. 你使用什麼方法或指令修改 sudoers ?
請貼上來完整指令

代码: 全选

su
visudo /etc/sudoers
2.
你修改 sudoers 期望達到麼目的 ?
开始尝试用visudo打开看看sudoers,但因来知道其操作方式,操作不当,退出后即出现了上述问题。

此后再尝试修改sudoers就使用vi了。
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: sudoers不知哪里错了

#6

帖子 vickycq » 2016-02-28 12:02

yangdawei 写了:source sudoers 报错信息:
sudoers 不是 bash 脚本
$ help source
source: source filename [arguments] - Execute commands from a file in the current shell.
Ubuntu 出现这种问题是比较难办的。因为默认没有 root 密码,sudoers 损坏就意味着丢失 root 权限。可用 pkexec 提权修复
Debian 问题不大,直接用 su 即可
sudoers: syntax error near line 9 <<<
这个原因未知,需再研究
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
yangdawei.hit
帖子: 245
注册时间: 2015-01-02 15:32
系统: Debian

Re: sudoers不知哪里错了

#7

帖子 yangdawei.hit » 2016-02-28 16:35

可能是文件之外的问题,因为工作需要,重做了系统。这个sudoers不搞清楚了轻易不能碰了。
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: sudoers不知哪里错了

#8

帖子 poloshiao » 2016-02-28 20:04

su
visudo /etc/sudoers
此后再尝试修改sudoers就使用vi了。
1. 這是錯誤的操作指令
1-1. 正確指令是
sudo visudo
1-1-1. 不必指名 /etc/sudoers
因為它 就專為修改 /etc/sudoers 而設
1-1-1-1. http://manpages.ubuntu.com/manpages/wil ... udo.8.html
visudo — edit the sudoers file

2. 在 Ubuntu 新手 對於 權限 / uid / gid 不熟悉前
不建議 使用 root 登入 也不建議 切換成 root 身份
2-1. 使用非 root 登入 需要 root 權限時 加 sudo / gksudo 在指令前面 參見
https://help.ubuntu.com/community/RootSudo#Usage
2-2. 如果要給登入的帳號 能夠使用 sudo / gksudo 行使 root 的權利
只要把該非 root 使用者帳號 使用 usermod 指令 加入 sudo 群組即可
http://manpages.ubuntu.com/manpages/wil ... mod.8.html
usermod - modify a user account
因为工作需要,重做了系统
3. 抱歉 太晚回覆你

4. 以後 有需要 再參閱
4-1. https://help.ubuntu.com/community/Sudoers
Sudoers
4-2. https://www.digitalocean.com/community/ ... and-centos
How To Edit the Sudoers File on Ubuntu and CentOS
4-3. 再強調 新手 不熟悉 ubuntu 權限 / uid / gid 前
不建議 使用 root 登入 也不建議 切換成 root 身份
4-4. 也不建議你 任意改變 /etc/sudoers 檔案
4-5. 提供前面文章 僅僅提供你參考 不是鼓勵你現在就動手去改它
yangdawei.hit
帖子: 245
注册时间: 2015-01-02 15:32
系统: Debian

Re: sudoers不知哪里错了

#9

帖子 yangdawei.hit » 2016-02-28 20:28

非常感谢poloshiao的耐心指导。
回复