博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux sudo命令
阅读量:6991 次
发布时间:2019-06-27

本文共 2790 字,大约阅读时间需要 9 分钟。

  sudo

       Instead of using the root user account, unprivileged users can be configured for using administrator permissions on specific tasks by using sudo. When sudo is configured, ordinary users have sudo privileges and to use these privileges, they will start the command using  sudo . So, instead of using commands like  useradd  as the root user, you use an ordinary user account and type  sudo useradd . This is definitely more secure because you will only be able to act as if you have administrator permissions while running this specific command.  

       When creating Linux users during the installation process, you can select to grant administrator permissions to that specific user. If you select to do so, the user will be able to use all administrator commands using sudo. It is also possible to set up sudo privileges after installation. To do that in a very easy way, you have to accomplish a simple two-step procedure:     

       1.   Make the administrative user account member of the group wheel by using  usermod -aG wheel user .     

       2.   Type  visudo  and make sure the line %wheel ALL=(ALL) ALL is included.

[rusky@rhel7 ~]$ useradd test   --普通账号rusky是没有权限添加用户的-bash: /usr/sbin/useradd: Permission denied[rusky@rhel7 ~]$ sudo useradd test  --使用sudo提升到administrator权限失败We trust you have received the usual lecture from the local SystemAdministrator. It usually boils down to these three things:    #1) Respect the privacy of others.    #2) Think before you type.    #3) With great power comes great responsibility.[sudo] password for rusky: rusky is not in the sudoers file.  This incident will be reported.   [rusky@rhel7 ~]$ id ruskyuid=1000(rusky) gid=1000(rusky) groups=1000(rusky)==========================================处理方法:[rusky@rhel7 ~]$ su -Password: Last login: Thu Jun 16 03:50:19 EDT 2016 from rhel7.com on pts/4[root@rhel7 ~]# usermod -aG wheel rusky     --执行这条命令[root@rhel7 ~]# visudo       --## Allows people in group wheel to run all commands%wheel  ALL=(ALL)       ALL[root@rhel7 ~]# su - ruskyLast login: Thu Jun 16 04:06:56 EDT 2016 on pts/4[rusky@rhel7 ~]$ useradd-bash: /usr/sbin/useradd: Permission denied[rusky@rhel7 ~]$ sudo useradd test   --使用sudo 添加用户正常[sudo] password for rusky:

 =========================

[root@rhel7 ~]#usermod -aG wheel rusky  ---修改用户,将用户rusky添加到附加组wheel组(系统默认就有这个组)

这个rusky用户是安装系统的过种中创建的;也可以在使用useradd -g root -G wheel -d /home/rusky2 -m rusky2 命令创建新用户时添加到附加wheel组。

-G, --groups GROUPS           new list of supplementary GROUPS

-a, --append                  append the user to the supplemental GROUPS

=====

[root@rhel7 ~]# visudo

## Sudoers allows particular users to run various commands as

## the root user, without needing the root password

. ...... 

## Allows people in group wheel to run all commands

%wheel  ALL=(ALL)       ALL   -- 取消注释此行

转载于:https://www.cnblogs.com/rusking/p/5591404.html

你可能感兴趣的文章
重构遗留代码(1):金牌大师
查看>>
go:数组
查看>>
网站重构的理解
查看>>
PAT L1-043. 阅览室
查看>>
linux 命令与文件的查询
查看>>
MYSQL数据库引擎 MYISAM和 INNODB区别
查看>>
设计模式之原型模式
查看>>
BootStrap常用组件及响应式开发
查看>>
TS学习之for..of
查看>>
OpenGL是什么?
查看>>
Oracle - 数据库巡检脚本
查看>>
提高系统性能:从数据访问层开始
查看>>
【转】IOS开发小技巧
查看>>
ECMAScript 类型转换
查看>>
Java的垃圾回收机制
查看>>
SQL Server 2005 的各种版本所支持的功能
查看>>
Java面向对象之多态
查看>>
第一次接触HBuild
查看>>
逆推 Gym 101102J
查看>>
CF 675 div2C 数学 让环所有值变为0的最少操作数
查看>>