一、sudo权限(只能由管理员操作)

  1. 操作对象 --> 命令(命令也是文件)

  2. 命令存放路径/sbin与/bin --> 只由root管理员用户操作

  3. 实际工作中,是不允许你使用root用户大量操作系统的,在使用到一些特殊命令需要使用root权限,

    这时sudo就发挥了其存在的作用

    也就是root管理员将部分命令授权于普通用户的过程

[root@hadoop09-linux bin]# su - eRrsr  # 使用普通用户去操作关机命令时
[eRrsr@hadoop09-linux ~]$ shutdown -r now
shutdown: Need to be root

  4. 使用root赋予普通用户权限

[eRrsr@hadoop09-linux ~]$ visudo  # 用户赋予权限(root用户操作),其实visudo命令操作的是/etc/sudoers文件
visudo: /etc/sudoers: Permission denied
visudo: /etc/sudoers: Permission denied
[eRrsr@hadoop09-linux ~]$ su -
Password:
[root@hadoop09-linux ~]# visudo ## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
## Examples are provided at the bottom of the file for collections
## of related commands, which can then be delegated out to particular
## users or groups.
##
## This file must be edited with the 'visudo' command.
...

  

...
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin ## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL    # 赋予权限,可以看到root用户具有所有权限,通过下面的查看赋值格式来分析:
                    # root 用户
                    # All(第一个) 就相当于Lisa用户的 各网段IP
                    #(All)(第二个) 用户的身份,(ALL)也就代表管理员身份,可写可不写
                    # ALL(最后一个) 具体的命令 (绝对路径:查看命令位置whereis或which)
...

  查看赋值格式

[root@hadoop09-linux ~]# man visudo  # 这里只是查看到visudo命令的相关信息
...
SEE ALSO
vi(1), sudoers(5), sudo(8), vipw(8) # sudoers(5) 5 代表配置文件,我们要查看的是这个5
---

  

[root@hadoop09-linux ~]# man 5 sudoers
...
jack CSNETS = ALL # CENTES 是网段的别名 ,就是说该条命令表示jack在这个网段下可以使用所有命令 The user jack may run any command on the machines in the CSNETS alias (the networks 128.138.243.0, 128.138.204.0, and 128.138.242.0). Of those
networks, only 128.138.204.0 has an explicit netmask (in CIDR notation) indicating it is a class C network. For the other networks in CSNETS,
the local machine’s netmask will be used during matching. lisa CUNETS = ALL The user lisa may run any command on any host in the CUNETS alias (the class B network 128.138.0.0). ... ...
  jack CSNETS = ALL The user jack may run any command on the machines in the CSNETS alias (the networks 128.138.243.0, 128.138.204.0, and 128.138.242.0). Of those
networks, only 128.138.204.0 has an explicit netmask (in CIDR notation) indicating it is a class C network. For the other networks in CSNETS,
the local machine’s netmask will be used during matching. Host_Alias CUNETS = 128.138.0.0/255.255.0.0
Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0 #!
Host_Alias SERVERS = master, mail, www, ns
Host_Alias CDROM = orion, perseus, hercules
...

  刚才普通用户eRrsr重启系统命令显示root用户操作,那么来给eRrsr授权吧

[eRrsr@hadoop09-linux ~]$ su -
Password:
[root@hadoop09-linux ~]# visudo
...
## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
## user MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
eRrsr ALL= /sbin/shutdown -r now
...
[root@hadoop09-linux ~]# su - eRrsr
[eRrsr@hadoop09-linux ~]$ sudo shutdown -r now We trust you have received the usual lecture from the local System
Administrator. 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 eRrsr: Broadcast message from root@hadoop09-linux.ibeifeng.com
(/dev/pts/1) at 5:53 ... The system is going down for reboot NOW!

  发现每次普通用户使用sudo时还要输入密码,那在赋予其不必输入密码权限

eRrsr   ALL=(root)      NOPASSWD:ALL

  查看当前用户被赋予了那些权限

[root@hadoop09-linux ~]# sudo -l
Matching Defaults entries for root on this host:
requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME
LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE",
env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin User root may run the following commands on this host:
(ALL) ALL
[root@hadoop09-linux ~]# su - eRrsr
[eRrsr@hadoop09-linux ~]$ sudo -l
Matching Defaults entries for eRrsr on this host:
requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME
LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE",
env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin User eRrsr may run the following commands on this host:
(root) /sbin/shutdown -r now
(root) NOPASSWD: ALL

Linux_sudo权限的更多相关文章

  1. 隐私泄露杀手锏 —— Flash 权限反射

    [简版:http://weibo.com/p/1001603881940380956046] 前言 一直以为该风险早已被重视,但最近无意中发现,仍有不少网站存在该缺陷,其中不乏一些常用的邮箱.社交网站 ...

  2. 【.net 深呼吸】限制执行代码的权限

    前面好几篇文章,老周都跟大伙伴们聊了跟应用程序域有关的话题,干脆咱们一聊到底吧,做学问就应该这样,有恒心. App Domain的创建新应用程序域的方法中,有一个特殊的重载: public stati ...

  3. Android 6.0 权限知识学习笔记

    最近在项目上因为6.0运行时权限吃了亏,发现之前对运行时权限的理解不足,决定回炉重造,重新学习一下Android Permission. 进入正题: Android权限 在Android系统中,权限分 ...

  4. Android数据存储之Android 6.0运行时权限下文件存储的思考

    前言: 在我们做App开发的过程中基本上都会用到文件存储,所以文件存储对于我们来说是相当熟悉了,不过自从Android 6.0发布之后,基于运行时权限机制访问外置sdcard是需要动态申请权限,所以以 ...

  5. Android权限管理之RxPermission解决Android 6.0 适配问题

    前言: 上篇重点学习了Android 6.0的运行时权限,今天还是围绕着Android 6.0权限适配来总结学习,这里主要介绍一下我们公司解决Android 6.0权限适配的方案:RxJava+RxP ...

  6. Android权限管理之Android 6.0运行时权限及解决办法

    前言: 今天还是围绕着最近面试的一个热门话题Android 6.0权限适配来总结学习,其实Android 6.0权限适配我们公司是在今年5月份才开始做,算是比较晚的吧,不过现在Android 6.0以 ...

  7. Android权限管理之Permission权限机制及使用

    前言: 最近突然喜欢上一句诗:"宠辱不惊,看庭前花开花落:去留无意,望天空云卷云舒." 哈哈~,这个和今天的主题无关,最近只要不学习总觉得生活中少了点什么,所以想着围绕着最近面试过 ...

  8. shiro权限管理框架与springmvc整合

    shiro是apache下的一个项目,和spring security类似,用于用户权限的管理‘ 但从易用性和学习成本上考虑,shiro更具优势,同时shiro支持和很多接口集成 用户及权限管理是众多 ...

  9. 尝试asp.net mvc 基于controller action 方式权限控制方案可行性

    微软在推出mvc框架不久,短短几年里,版本更新之快,真是大快人心,微软在这种优秀的框架上做了大量的精力投入,是值得赞同的,毕竟程序员驾驭在这种框架上,能够强力的精化代码,代码层次也更加优雅,扩展较为方 ...

随机推荐

  1. Effective C++ 之 0 导读(Introduction)

    Effective C++ 导读 (Introduction) 术语(terminology) 声明式 (declaration) 是告诉编译器某个东西的名称和类型(type),但略去细节.以下都是声 ...

  2. easyui tree折叠

    标签 <div id="buildDiv" data-options="region:'center'" title="楼栋权限" s ...

  3. Java中的wait和sleep

    sleep()和wait() 首先,Java中的多线程是一种抢占式的机制,而不是分时机制.抢占式的机制是有多个线程处于可运行状态,但是只有一个线程在运行. 这种机制决定了,对于同一对象的多线程访问,必 ...

  4. HTML的格式、内容容器、表格标签

    HTML(Hyper Text Markup Language,超文本标记语言)超指的是超链接. <html>    --开始标签 <head> 网页上的控制信息 <ti ...

  5. ubuntu安装shadowshocks-qt5

    sudo add-apt-repository ppa:hzwhuang/ss-qt5 sudo apt-get update sudo apt-get install shadowsocks-qt5 ...

  6. flv文件格式解析!!!

    flv头 FLV header 总体上看,FLV包括文件头(File Header)和文件体(File Body)两部分,其中文件体由一系列的Tag组成. Signature: FLV 文件的前3个字 ...

  7. Android 插件化 动态升级

    最新内容请见原文:Android 插件化 动态升级 不少朋友私信以及 Android开源交流几个 QQ 群 中都问到这个问题,这里简单介绍下 1.作用 大多数朋友开始接触这个问题是因为 App 爆棚了 ...

  8. nefu 197 KMP

    Description 在信息检索系统中一个很重要的环节就是关键字符串的查找,从而很多对自己有用的信息.给你一个很长的一段文字, 和一个关键信息字符串,现在要你判断这段文字里面是否有关键字符串. In ...

  9. jade学习01

    编写 简单例子 doctype html html head title learn jade body h1 learn jade 常用命令 编译: jade index.jade //默认编译成压 ...

  10. javascript关键字和保留字

    1 关键字breakcasecatchcontinuedefaultdeletedoelsefinallyforfunctionifininstanceofnewreturnswitchthisthr ...