萌新请教个问题,有关sudo
Tofloor
poster avatar
fragments1611
deepin
2018-04-25 03:18
Author
本帖最后由 fragments1611 于 2018-4-25 00:36 编辑

跟着鸟叔学,学到sudo这儿,问一下/etc/sudoers里 %sudo   ALL=(ALL:ALL) ALL 这个%sudo是啥意思?为啥登录系统的用户,能默认用sudo,如果不设置/sudoers文件,不应该只有root有权限用sudo么。
Reply Favorite View the author
All Replies
avatar
RedPanda
deepin
2018-04-25 03:24
#1
1.指的是如何给某个用户加sudo权限
Reply View the author
avatar
RedPanda
deepin
2018-04-25 03:27
#2
2.sudo就是给某个用户提高权限,如果不设置当然就只有root才有最高权限啊。
Reply View the author
avatar
liuguangjingshang
deepin
2018-04-25 06:43
#3
百分号(%)后面的sudo指的是用户组sudo,这个用户组里的用户可以使用sudo命令,往下面翻配置文档,应该还能看到其他的用户组,比如wheel用户组(#%wheel   ALL=(ALL:ALL) ALL),创建新用户的时候添加-G后缀将其同时添加到wheel组,修改sudoer文件将前的注释#去掉,则此用户可使用sudo命令切换到root用户
  1. 代码这一行怎么删.jpg
Copy the Code

Reply View the author
avatar
fragments1611
deepin
2018-04-25 08:29
#4
windcz91 发表于 2018-4-24 19:27
2.sudo就是给某个用户提高权限,如果不设置当然就只有root才有最高权限啊。

我看了下配置文件,里面好像只有%sudo 我自己的账号是gxy用户组也是gxy 配置文件里没有%gxy 为什么却能用sudo?
Reply View the author
avatar
fragments1611
deepin
2018-04-25 08:32
#5
本帖最后由 fragments1611 于 2018-4-25 00:34 编辑
windcz91 发表于 2018-4-24 19:27
2.sudo就是给某个用户提高权限,如果不设置当然就只有root才有最高权限啊。

我发现我问题问错了……如果没设置sudoers不是应该只有root才能用sudo么,为啥我现在用户是gxy也能用sudo.
Reply View the author
avatar
fragments1611
deepin
2018-04-25 08:33
#6
fragments1611 发表于 2018-4-25 00:32
我发现我问题问错了……如果我设置sudoers不是应该只有root才能用sudo么,为啥我现在用户是gxy也能用sudo ...

如果没设置sudoers不是应该只有root才能用sudo么,为啥我现在用户是gxy也能用sudo.
Reply View the author
avatar
fragments1611
deepin
2018-04-25 08:36
#7
https://bbs.deepin.org/post/155686
百分号(%)后面的sudo指的是用户组sudo,这个用户组里的用户可以使用sudo命令,往下面翻配置文档,应该还能 ...

继续往下翻没有哎
Reply View the author
avatar
liuguangjingshang
deepin
2018-04-26 20:12
#8
我之前用的是arch linux,不知道这两个文件是不是不一样,但应该道理都是一样的,可能没有wheel,也可能有其他的组,可是今天终端打不开了,也获得不了打开的权限,就很尴尬,不知道什么原因
Reply View the author
avatar
liuguangjingshang
deepin
2018-04-30 02:49
#9
本帖最后由 liuguangjingshang 于 2018-4-29 19:02 编辑
https://bbs.deepin.org/post/155686
如果没设置sudoers不是应该只有root才能用sudo么,为啥我现在用户是gxy也能用sudo. ...



sudoers的配置文件显示只有root用户和隶属于sudo组的用户才可以使用sudo命令;



装系统时建立的用户ms加到了sudo组,所以可以使用sudo命令;
新建的用户mss为指派分组,不在sudo组中,不能使用sudo命令;
使用sudo usermod -a -G sudo mss将mss加到sudo组中,才能使用sudo命令;同理,也可以在sudoers里追加相应的组或者用户,方法如下:
1)追加用户sm:
sm ALL=(ALL:ALL) ALL
2)追加用户msgroups:
%msgroups   ALL=(ALL:ALL) ALL

保存后即可使用root权限
  1. ms@ms-PC ~> sudo useradd mss
  2. ms@ms-PC ~> sudo passwd mss
  3. 输入新的 UNIX 密码:
  4. 重新输入新的 UNIX 密码:
  5. Sorry, passwords do not match
  6. passwd:鉴定令牌操作错误
  7. passwd:密码未更改
  8. ms@ms-PC ~> sudo userdel mss
  9. ms@ms-PC ~> sudo useradd sm
  10. ms@ms-PC ~> sudo passwd sm
  11. 输入新的 UNIX 密码:
  12. 重新输入新的 UNIX 密码:
  13. passwd:已成功更新密码
  14. ms@ms-PC ~> groups sm
  15. sm : sm
  16. ms@ms-PC ~> su sm
  17. 密码:
  18. $ sudo passwd root

  19. 我们信任您已经从系统管理员那里了解了日常注意事项。
  20. 总结起来无外乎这三点:

  21.     #1) 尊重别人的隐私。
  22.     #2) 输入前要先考虑(后果和风险)。
  23.     #3) 权力越大,责任越大。

  24. [sudo] sm 的密码:
  25. sm 不在 sudoers 文件中。此事将被报告。
  26. $ whoami
  27. sm
  28. $ groups
  29. sm
  30. $ exit
  31. ms@ms-PC ~> sudo echo '%sm ALL=(ALL:ALL) ALL' >> /etc/sudoers
  32. An error occurred while redirecting file '/etc/sudoers'
  33. open: Permission denied
  34. ms@ms-PC ~> su
  35. 密码:
  36. root@ms-PC:/home/ms# sudo echo '%sm ALL=(ALL:ALL) ALL' >> /etc/sudoers
  37. root@ms-PC:/home/ms# cat /etc/sudoers
  38. #
  39. # This file MUST be edited with the 'visudo' command as root.
  40. #
  41. # Please consider adding local content in /etc/sudoers.d/ instead of
  42. # directly modifying this file.
  43. #
  44. # See the man page for details on how to write a sudoers file.
  45. #
  46. Defaults        env_reset
  47. Defaults        mail_badpass
  48. Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

  49. # Host alias specification

  50. # User alias specification

  51. # Cmnd alias specification

  52. # User privilege specification
  53. root    ALL=(ALL:ALL) ALL

  54. # Allow members of group sudo to execute any command
  55. %sudo   ALL=(ALL:ALL) ALL

  56. # See sudoers(5) for more information on "#include" directives:

  57. #includedir /etc/sudoers.d
  58. %sm ALL=(ALL:ALL) ALL
  59. root@ms-PC:/home/ms# su sm
  60. $ whoami
  61. sm
  62. $ groups
  63. sm
  64. $ sudo passwd root
  65. [sudo] sm 的密码:
  66. 输入新的 UNIX 密码:
  67. 重新输入新的 UNIX 密码:
  68. passwd:已成功更新密码
Copy the Code











Reply View the author