【原创】Linux基础之sudo
sudo允许用户以其他用户的身份(比如root)执行命令,比如切换用户、执行命令、读写文件等;
配置
sudo配置在:/etc/sudoers
## 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.
...
## 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
...
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
从这个配置文件可以看到3点:
- 配置的格式(user MACHINE=COMMANDS)以及示例(在末尾附近),比如root的权限;
- /etc/sudoers.d/* 这个目录下边的文件也会被加载,这样就可以把不同类别的权限配置分开到不同的文件;
- 使用visudo编辑,使用vi或vim编辑也可以,不过visudo在保存前会做检查,如果配置有问题会报错,直接保存错误的配置可能导致难以预料的后果,千万不要尝试;
Options are:
(e)dit sudoers file again
e(x)it without saving changes to sudoers file
(Q)uit and save changes to sudoers file (DANGER!)What now?
常用场景
1 切换用户
username ALL=(root) NOPASSWD: /bin/su - targetuser
允许username切换到targetuser
%groupname ALL=(root) NOPASSWD: /bin/su - targetuser
允许groupname里边的用户切换到targetuser
2 执行命令
username ALL=(root) NOPASSWD: /usr/sbin/iptables
允许username执行iptables命令
【原创】Linux基础之sudo的更多相关文章
- Linux基础命令---sudo
sudo sudo允许用户以超级用户或安全策略指定的另一个用户的身份执行命令.Sudo支持安全策略插件和输入/输出日志的插件.第三方可以开发和分发自己的策略和I/O日志插件,以便与sudo前端无缝地工 ...
- [转帖]linux基础知识大纲
linux基础知识大纲 https://blog.csdn.net/CSDN___LYY/article/details/80810403 1.Linux操作系统概述Linux操作系统的发展过程.创始 ...
- Linux课程实践一:Linux基础实践(SSH)
一.SSH服务 1. 安装SSH (1)查看是否已经安装过ssh服务 rpm -qa |grep ssh (2)进行安装 sudo apt-get install openssh-server Ubu ...
- 买错的电影票,含着泪也得看-LAMP搭建&Linux基础
hi 没说过,上周五室友过生请客,在龙湖里吃嗨了喝爽了,回去的路上侃侃而谈.说好的这周一起去看年内最后的大片,火星救援的,谁知道老子眼神不好,买错了电影的时间...把周六的约定提前到了今儿个下午,ma ...
- Linux课程实践一:Linux基础实践(基础操作)
一.软件源维护 1. 基本操作 (1)查看源列表 sudo vim /etc/apt/sources.list deb:二进制软件安装包 deb-src:源码包 (2)备份软件源列表 sudo cp ...
- 实践一:Linux基础实践
一.Linux基础实践 1.1 1. 掌握软件源的维护方法,配置系统使用软件源镜像.掌握通过软件源来查找,安装,卸载,更新软件的方法. 这部分内容在许多学长学姐的报告里都有很详细的讲解,我在此就不赘述 ...
- Linux基础精华
Linux基础精华 (继续跟新中...) 常用命令: Linux shell 环境 让你提升命令行效 率的 Bash 快捷键 [完整版] 设置你自己的liux alias Linux的Find使用 L ...
- Linux基础入门
第一节,linux系统简介 一.实验内容 了解 Linux 的历史,Linux 与 Windows 的区别等入门知识. 二.实验要求 阅读linux简介与历史 三.实验步骤 (一).Linux 为何物 ...
- Linux及安全——Linux基础实践
Linux及安全——Linux基础实践 一.实践一:掌握软件源的维护方法,配置系统使用教育网内的软件源镜像.掌握通过软件源来查找,安装,卸载,更新软件的方法. 1.软件源的维护方法 Ubuntu的软件 ...
随机推荐
- 07-JavaScript之常用内置对象
JavaScript之常用内置对象 1.数组Array 1.1数组的创建方式 // 直接创建数组 var colors = ['red', 'blue', 'green']; console.log( ...
- 手动用tomcat启动war包,无法访问web项目
先说一下自己采的小坑,网上大多解答都是复制来复制去,不说重点在哪.我这里简单总结下访问路径问题 一.用idea打成war包,具体步骤如下图: 步骤:在项目配置选Artifacts新建Web Appli ...
- Python——高阶函数——map filter zip
一.map函数 1.作用:它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回. 2.实例 def f(x): return x* ...
- Python——sys模块
七.sys模块 sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传递参数. sys.exit([arg]): 程序中间的退出,arg=0为正常退出. sys.getdefaulten ...
- ObjectARX® for Beginners: An Introduction
转:ObjectARX® for Beginners: An Introduction Lee Ambrosius – Autodesk, Inc. CP4164-L Objec ...
- linux中的&&,|| 与 () 命令
用&&连接两个命令,前一命令执成功(返回0)下一命令才会执行, 如 date && echo 1 会打印1,而data && echo 2不会打印2 & ...
- 打开mac上面的apache 服务器
1. apache 服务器在系统安装的时候就默认安装了 config 文件未知: /etc/apache2/httpd.conf 2. 编辑配置文件 httpd.conf 2.1 查找 Docum ...
- 机器学习---文本特征提取之词袋模型(Machine Learning Text Feature Extraction Bag of Words)
假设有一段文本:"I have a cat, his name is Huzihu. Huzihu is really cute and friendly. We are good frie ...
- 「CF1154F」Shovels Shop【背包DP】
题目链接 [洛谷传送门] 题解 非常简单的背包. \(f[i]\)表示购买\(i\)个物品所需要最少的花费. 不考虑免费的限制条件,那么一定是选择前\(k\)个双鞋子. 那么加入免费的条件,那么还是要 ...
- [hashcat]基于字典和暴力破解尝试找到rar3-hp的压缩包密码
1.使用rar2john找到md5 2.基于字典 hashcat -a 0 -m 12500 /root/Desktop/md5.txt /usr/share/wordlists/weakpass.t ...