每天学五分钟 Liunx 011 | sudo
[root@controller-0 sudoers.d]# su --help
Usage:
su [options] [-] [USER [arg]...] Change the effective user id and group id to that of USER.
A mere - implies -l. If USER not given, assume root. Options:
-m, -p, --preserve-environment do not reset environment variables
-g, --group <group> specify the primary group
-G, --supp-group <group> specify a supplemental group -, -l, --login make the shell a login shell
-c, --command <command> pass a single command to the shell with -c
--session-command <command> pass a single command to the shell with -c
and do not create a new session
-f, --fast pass -f to the shell (for csh or tcsh)
-s, --shell <shell> run shell if /etc/shells allows it -h, --help display this help and exit
-V, --version output version information and exit
[lianhua@***n ~]$ su - root
Password:
Last login: Sat Mar 7 17:55:48 CST 2020 on pts/0
[root@*** ~]# env
XDG_SESSION_ID=5763
HOSTNAME=***
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
http_proxy=http://10.110.***.***
USER=root
LS_COLORS=36:*.xspf=01;36:
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
LESSOPEN=||/usr/bin/lesspipe.sh %s
_=/bin/env
[lianhua@*** ~]$ su root
Password:
[root@*** ~]# env
XDG_SESSION_ID=5763
HOSTNAME=***
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
USER=lianhua
http_proxy=http://10.110.***.***
LS_COLORS=36:*.xspf=01;36:
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/lianhua/.local/bin:/home/lianhua/bin
MAIL=/var/spool/mail/lianhua
PWD=/home/lianhua
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
HOME=/root
SHLVL=2
LOGNAME=lianhua
LESSOPEN=||/usr/bin/lesspipe.sh %s
_=/bin/env
Options:
-A, --askpass use a helper program for password prompting
-b, --background run command in the background
-C, --close-from=num close all file descriptors >= num
-E, --preserve-env preserve user environment when running command
--preserve-env=list preserve specific environment variables
-e, --edit edit files instead of running a command
-g, --group=group run command as the specified group name or ID
-H, --set-home set HOME variable to target user's home dir
-h, --help display help message and exit
-h, --host=host run command on host (if supported by plugin)
-i, --login run login shell as the target user; a command may also be specified
-K, --remove-timestamp remove timestamp file completely
-k, --reset-timestamp invalidate timestamp file
-l, --list list user's privileges or check a specific command; use twice for longer format
-n, --non-interactive non-interactive mode, no prompts are used
-P, --preserve-groups preserve group vector instead of setting to target's
-p, --prompt=prompt use the specified password prompt
-r, --role=role create SELinux security context with specified role
-S, --stdin read password from standard input
-s, --shell run shell as the target user; a command may also be specified
-t, --type=type create SELinux security context with specified type
-T, --command-timeout=timeout terminate command after the specified time limit
-U, --other-user=user in list mode, display privileges for user
-u, --user=user run command (or edit file) as specified user name or ID
-V, --version display version information and exit
-v, --validate update user's timestamp without running a command
-- stop processing command line arguments
[lianhua@*** ~]$ sudo passwd
[sudo] password for lianhua:
Sorry, user lianhua is not allowed to execute '/bin/passwd' as root on controller-0-forestgreen.
[root@test ~]visudo
...
root ALL=(ALL) ALL
...
用户账号 登陆者的来源主机名=[可切换的身份] 可执行的命令
root ALL = (ALL) ALL
[root@*** ~]visudo
...
huasheng ALL=(ALL) NOPASSWD:/usr/sbin/visudo
...
[root@*** ~]# hostname
test
[root@*** ~]# hostname -I
10.57.0.1
[root@*** ~]# visudo
...
huasheng 10.57.0.1=(ALL) NOPASSWD:/usr/sbin/visudo
...
[root@*** ~]# su - huasheng
Last login: Sat Mar 7 16:06:10 CST 2020 on pts/0
[huasheng@*** ~]$ sudo visudo
visudo: /etc/sudoers.tmp unchanged
[huasheng@*** ~]# visudo
...
huasheng 10.57.1.1=(ALL) NOPASSWD:/usr/sbin/visudo
...
[huasheng@*** ~]$ sudo visudo
[sudo] password for huasheng:
huasheng is not allowed to run sudo on test. This incident will be reported.
[root@test ~]# visudo
[root@test ~]# su - huasheng
Last login: Sat Mar 7 19:27:29 CST 2020 on pts/0
[huasheng@test ~]$ sudo visudo
[sudo] password for huasheng:
Sorry, user huasheng is not allowed to execute '/sbin/visudo' as root on test.
[lianhua@test ~]$ su - huasheng
Password:
Last login: Sat Mar 7 19:52:44 CST 2020 on pts/0
[huasheng@test ~]$ which su
/bin/su
[huasheng@controller-0-forestgreen ~]$ sudo visudo
...
lianhua ALL=(ALL) NOPASSWD: /bin/su
... [huasheng@test ~]$ exit
logout
[lianhua@test ~]$ sudo su
[root@test lianhua]#
[root@test lianhua]# visudo
...
lianhuasheng ALL=(ALL) NOPASSWD: /bin/su
...
[root@test lianhua]# groupadd ADMINGROUP
[root@test lianhua]# visudo
...
%ADMINGROUP ALL=(ALL) NOPASSWD: /bin/su, !/bin/passwd, !/bin/passwd root
...
[root@test lianhua]# usermod -G ADMINGROUP lianhua
[root@test lianhua]# usermod -G ADMINGROUP huasheng
[root@test lianhua]# usermod -G ADMINGROUP lianhuasheng
[root@test lianhua]# su - lianhua
Last login: Sat Mar 7 19:56:00 CST 2020 on pts/0
[lianhua@test ~]$ sudo su
[root@test lianhua]#
[root@test ~]# cat /etc/sudoers | grep sudoers.d
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
[root@test lianhua]# cd /etc/sudoers.d/
[root@test sudoers.d]# vi ADMINGROUP
%ADMINGROUP ALL=(ALL) NOPASSWD: /bin/su
[root@test sudoers.d]# visudo
[root@test sudoers.d]# su - lianhua
Last login: Sat Mar 7 20:17:35 CST 2020 on pts/0
[lianhua@test ~]$ sudo su
[root@test lianhua]#
每天学五分钟 Liunx 011 | sudo的更多相关文章
- 如何从40亿整数中找到不存在的一个 webservice Asp.Net Core 轻松学-10分钟使用EFCore连接MSSQL数据库 WPF实战案例-打印 RabbitMQ与.net core(五) topic类型 与 headers类型 的Exchange
如何从40亿整数中找到不存在的一个 前言 给定一个最多包含40亿个随机排列的32位的顺序整数的顺序文件,找出一个不在文件中的32位整数.(在文件中至少确实一个这样的数-为什么?).在具有足够内存的情况 ...
- 零元学Expression Blend 4 - Chapter 42 五分钟快速完成扇形变圆形动画
原文:零元学Expression Blend 4 - Chapter 42 五分钟快速完成扇形变圆形动画 零元学Expression Blend 4 - Chapter 42 五分钟快速完成扇形变圆形 ...
- 五分钟学Java:如何才能学好Java Web里这么多的技术
原创声明 本文作者:黄小斜 转载请务必在文章开头注明出处和作者. 系列文章介绍 本文是<五分钟学Java>系列文章的一篇 本系列文章主要围绕Java程序员必须掌握的核心技能,结合我个人三年 ...
- 《sed的流艺术之一》-linux命令五分钟系列之二十一
本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...
- 五分钟搭建一个基于BERT的NER模型
BERT 简介 BERT是2018年google 提出来的预训练的语言模型,并且它打破很多NLP领域的任务记录,其提出在nlp的领域具有重要意义.预训练的(pre-train)的语言模型通过无监督的学 ...
- 一门能让你五分钟学会的语言-Brainfuck
看到标题,不出意外的话,你肯定开始骂我了:**标题党,什么编程语言五分钟就能学会? 其实我本来也是不相信的,但是学过了才知道这是真的. 1.Brainfuck 看到这个小标题,不要误会,我没有骂人. ...
- 用五分钟重温委托,匿名方法,Lambda,泛型委托,表达式树
这些对老一代的程序员都是老生常谈的东西,没什么新意,对新生代的程序员却充满着魅力.曾经新生代,好多都经过漫长的学习,理解,实践才能掌握委托,表达式树这些应用.今天我尝试用简单的方法叙述一下,让大家在五 ...
- [分享] 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例)
[分享] 史上最简单的封装教程,五分钟学会封装系统(以封装Windows 7为例) 踏雁寻花 发表于 2015-8-23 23:31:28 https://www.itsk.com/thread-35 ...
- JVM内存管理------GC算法精解(五分钟让你彻底明白标记/清除算法)
相信不少猿友看到标题就认为LZ是标题党了,不过既然您已经被LZ忽悠进来了,那就好好的享受一顿算法大餐吧.不过LZ丑话说前面哦,这篇文章应该能让各位彻底理解标记/清除算法,不过倘若各位猿友不能在五分钟内 ...
- 转帖:用五分钟重温委托,匿名方法,Lambda,泛型委托,表达式树
用五分钟重温委托,匿名方法,Lambda,泛型委托,表达式树 这些对老一代的程序员都是老生常谈的东西,没什么新意,对新生代的程序员却充满着魅力.曾经新生代,好多都经过漫长的学习,理解,实践才能掌握委托 ...
随机推荐
- 文心一言 VS 讯飞星火 VS chatgpt (156)-- 算法导论12.3 3题
三.用go语言,对于给定的 n 个数的集合,可以通过先构造包含这些数据的一棵二叉搜索树(反复使用TREE-INSERT 逐个插入这些数),然后按中序遍历输出这些数的方法,来对它们排序.这个排序算法的最 ...
- Asp.net core Webapi 如何执行定时任务?
前言 在计算机系统中,定时执行一些后台任务是很常见的场景,比如定时发送邮件.备份数据等等. 那么,.NET 技术如何通过编程灵活地实现项目里复杂的自定义任务呢? 如果是 Windows 生态,通常来说 ...
- 1.7每日总结-vue链mysql4
新建/server/router.js,用于配置对应路由let express = require('express')let router = express.Router()let user = ...
- QRCoder1.4.3生成二维码,不依赖System.Drawing,解决"未能找到类型或命名空间名QRCode","及ImageFormatPng仅在windows上受支持"
生成二维码1(简单) 包引用: <PackageReference Include="QRCoder" Version="1.4.3" /> usi ...
- 第3章-图形处理单元-3.2-GPU管线概览
3.2 GPU管线概览 GPU实现了第2章中描述的概念:几何处理.光栅化和像素处理流水线阶段.这些阶段被分为几个具有不同程度的可配置性或可编程性的硬件阶段.图3.2显示了根据可编程或可配置程度对各个阶 ...
- DWS临时内存不可用报错: memory temporarily unavailable
本文分享自华为云社区<DWS临时内存不可用报错: memory temporarily unavailable>,作者:漫天. 1.定位报错的DN/CN 当出现memory tempora ...
- 实战案例丨分布式系统中如何用python实现Paxos
摘要:提到分布式算法,就不得不提 Paxos 算法,在过去几十年里,它基本上是分布式共识的代 名词,因为当前最常用的一批共识算法都是基于它改进的.比如,Fast Paxos 算法. Cheap Pax ...
- 云图说|云数据库MySQL内核小版本升级全攻略
摘要:华为云数据库MySQL支持自动或手动升级内核小版本,内核小版本的升级涉及性能提升.新功能或问题修复等. 华为云有新的内核小版本发布时,您可以在"实例管理"页面看到内核小版本升 ...
- Spring Cache设计之美,你品,你细品…
摘要:Spring Cache的功能很强大,设计也非常优雅,特别适合缓存控制没有那么细致的场景,比如门户首页,偏静态展示页面,榜单等等 本文分享自华为云社区<品味 spring cache设计之 ...
- 云小课|打造企业数据“高内聚,低耦合”--试试GaussDB(DWS)逻辑集群,实现数据物理隔离
阅识风云是华为云信息大咖,擅长将复杂信息多元化呈现,其出品的一张图(云图说).深入浅出的博文(云小课)或短视频(云视厅)总有一款能让您快速上手华为云.更多精彩内容请单击此处. 摘要:逻辑集群是基于No ...