Linux_sudo权限
一、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权限的更多相关文章
- 隐私泄露杀手锏 —— Flash 权限反射
[简版:http://weibo.com/p/1001603881940380956046] 前言 一直以为该风险早已被重视,但最近无意中发现,仍有不少网站存在该缺陷,其中不乏一些常用的邮箱.社交网站 ...
- 【.net 深呼吸】限制执行代码的权限
前面好几篇文章,老周都跟大伙伴们聊了跟应用程序域有关的话题,干脆咱们一聊到底吧,做学问就应该这样,有恒心. App Domain的创建新应用程序域的方法中,有一个特殊的重载: public stati ...
- Android 6.0 权限知识学习笔记
最近在项目上因为6.0运行时权限吃了亏,发现之前对运行时权限的理解不足,决定回炉重造,重新学习一下Android Permission. 进入正题: Android权限 在Android系统中,权限分 ...
- Android数据存储之Android 6.0运行时权限下文件存储的思考
前言: 在我们做App开发的过程中基本上都会用到文件存储,所以文件存储对于我们来说是相当熟悉了,不过自从Android 6.0发布之后,基于运行时权限机制访问外置sdcard是需要动态申请权限,所以以 ...
- Android权限管理之RxPermission解决Android 6.0 适配问题
前言: 上篇重点学习了Android 6.0的运行时权限,今天还是围绕着Android 6.0权限适配来总结学习,这里主要介绍一下我们公司解决Android 6.0权限适配的方案:RxJava+RxP ...
- Android权限管理之Android 6.0运行时权限及解决办法
前言: 今天还是围绕着最近面试的一个热门话题Android 6.0权限适配来总结学习,其实Android 6.0权限适配我们公司是在今年5月份才开始做,算是比较晚的吧,不过现在Android 6.0以 ...
- Android权限管理之Permission权限机制及使用
前言: 最近突然喜欢上一句诗:"宠辱不惊,看庭前花开花落:去留无意,望天空云卷云舒." 哈哈~,这个和今天的主题无关,最近只要不学习总觉得生活中少了点什么,所以想着围绕着最近面试过 ...
- shiro权限管理框架与springmvc整合
shiro是apache下的一个项目,和spring security类似,用于用户权限的管理‘ 但从易用性和学习成本上考虑,shiro更具优势,同时shiro支持和很多接口集成 用户及权限管理是众多 ...
- 尝试asp.net mvc 基于controller action 方式权限控制方案可行性
微软在推出mvc框架不久,短短几年里,版本更新之快,真是大快人心,微软在这种优秀的框架上做了大量的精力投入,是值得赞同的,毕竟程序员驾驭在这种框架上,能够强力的精化代码,代码层次也更加优雅,扩展较为方 ...
随机推荐
- Java Web 项目获取运行时路径 classpath
假设资源文件放在maven工程的 src/main/resources 资源文件夹下,源码文件放在 src/main/java/下, 那么java文件夹和resources文件夹在运行时就是class ...
- 处理FF margin-top下降问题
处理DIV子级ZImargin-top下降,父级更着下降问题 html结构如下 <div id="top"> <div id="zi"> ...
- Confluent Platform 3.0支持使用Kafka Streams实现实时的数据处理(最新版已经是3.1了,支持kafka0.10了)
来自 Confluent 的 Confluent Platform 3.0 消息系统支持使用 Kafka Streams 实现实时的数据处理,这家公司也是在背后支撑 Apache Kafka 消息框架 ...
- 【转】Kylin的Hierarchies,Derived维度方面配置优化
http://blog.csdn.net/jiangshouzhuang/article/details/51286150 Hierarchies: 理论上对于N维度,我们可以进行2的N次方的维度组合 ...
- vim 清空
插入模式 首先执行gg 跳至文件首行 然后执行dG就清空了整个文件 还有一种方法就要退出VIM,然后使用echo > file ,这样也能快速清空文件内容
- 【noip暑假tarjan专题】
%%%奎老师 A:傻逼缩点...傻逼编译器卡我next... B:就是这道奎老师没讲清楚的题,明明小朋友们都一A嘛,,,明明细节有很多嘛,,,怎么都这么熟练啊. C:本质还是B,换了个马甲而已. D: ...
- Codeforces Round #337 (Div. 2)
水 A - Pasha and Stick #include <bits/stdc++.h> using namespace std; typedef long long ll; cons ...
- POJ 1014 Dividing(多重背包)
Dividing Description Marsha and Bill own a collection of marbles. They want to split the collectio ...
- BZOJ4665 : 小w的喜糖
考虑枚举哪些人一定不合法,那么方案数可以通过简单的排列组合算出. 于是设$f[i][j]$表示前$i$种糖果,一共有$j$个人一定不合法的方案数,但是这样并不能保证其他人一定合法,所以需要进行容斥. ...
- js/jQuery判断浏览器名称、内核版本、浏览器壳
1.js方法 /* 判断浏览器名称和版本 目前只能判断:ie/firefox/chrome/opera/safari 2012年5月16日23:47:08 浏览器内核UA:UA; 浏览器内核名称:NV ...