Deepin 用户史怎么使用sudo 的
Tofloor
poster avatar
daloyanf
deepin
2018-04-29 19:06
Author
我看了/etc/sudoers  这个文件      和/etc/sudoer.d/ 里面的文件都没我的用户名,为何我可以使用sudo


Reply Favorite View the author
All Replies
avatar
woodelf
deepin
2018-04-29 19:18
#1
加了sudo组
Reply View the author
avatar
daloyanf
deepin
2018-04-30 01:39
#2

没有啊  deepin 的用户名就是一个用户组
Reply View the author
avatar
liuguangjingshang
deepin
2018-04-30 02:38
#3
本帖最后由 liuguangjingshang 于 2018-4-29 18:41 编辑


装系统时建立的用户ms加到了sudo组,所以可以使用sudo命令;
新建的用户mss为指派分组,不在sudo组中,不能使用sudo命令;
使用sudo usermod -a -G sudo mss将mss加到sudo组中,才能使用sudo命令
Reply View the author
avatar
liuguangjingshang
deepin
2018-04-30 02:45
#4
本帖最后由 liuguangjingshang 于 2018-4-29 19:04 编辑


sudoers的配置文件显示只有root用户和隶属于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

  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
avatar
sz******iy@vip.qq.com
deepin
2018-04-30 20:39
#5
  • 查看系统中的所有用户 cat /etc/passwd
  • 查看系统中的所有分组 cat /etc/group 也可以利用终端的自动补全功能输入groupmod后按下Tab列出所有组名。
    PS:不在adm和sudo组中的用户,无法使用sudo命令
  • 添加组 groupadd 组名; 删除组 groupdel 组名
  • 查看用户所在组 groups 用户名;查看分组中的账户 cat /etc/group | grep 组名 本质上是穿给管道给grep进行搜索。
  • 修改用户默认组 usermod -g 组名 用户名 ;给用户添加一个组 usermod -a -G 组名 用户名


Reply View the author