sudo 命令详解
在linux系统中,由于root的权限过大,一般情况都不使用它。只有在一些特殊情况下才采用登录root执行管理任务,一般情况下临时使用root权限多采用su和sudo命令。
一、su和sudo命令对比:
在普通用户下输入su命令后,会提示输入root账户的密码,然后就进入特权模式(跟用root登录系统完全一样),输入exit或者su - user 退出:
$ su -
Password:
ls /root
anaconda-ks.cfg install.log install.log.syslog
exit
$ ls /root
ls: cannot open directory /root: Permission denied #提示没有权限
而采用sudo命令,只需输入当前用户的密码(也可以配置为不输入密码)即可执行需要root权限执行的命令:
“`
ls /root
ls: cannot open directory /root: Permission denied #提示没有权限sudo ls /root
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 oracle: #输入普通用户oracle的密码
anaconda-ks.cfg install.log install.log.syslog
通过上面的对比可以看出,sudo比su有很多优点:
- 普通用户不需要知道root的密码即可执行需要root权限的命令;
- 不会因忘记退出而采用root执行了会引起破坏性的命令(初学linux经常犯这个错)
二、配置普通用户有使用sudo命令的权限:
在linux系统中,新建用户并没有执行sudo权限,如新建一个AAA的用户,输入sudo命令会有如下提示:
```
aaa is not in the sudoers file. This incident will be reported.
```
这句的意思是在sudoers文件中不存在aaa这个用户,这个时间会被报告给管理员。
既然知道问题处于sudoers这个文件,那我们就看看这个文件为何方神圣:
```
[root@dbs aaa]# vi /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.
## Host Aliases
## Groups of machines. You may prefer to use hostnames (perhaps using
## wildcards for entire domains) or IP addresses instead.
# Host_Alias FILESERVERS = fs1, fs2
# Host_Alias MAILSERVERS = smtp, smtp2
## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS
# User_Alias ADMINS = jsmith, mikem
输入i,对文件进行编辑,发现底部有只读提示:
-- INSERT -- W10: Warning: Changing a readonly file
应该是没有权限,退出编辑状态后查看权限:
[root@dbs aaa]# ll /etc/sudoers
-r–r—–. 1 root root 3825 Jul 22 01:05 /etc/sudoers
原来root也只有只读权限,难怪,首先修改权限以让root有完全控制权限:
[root@dbs aaa]#chmod 740 /etc/sudoers
再次编辑,这次没有出现只读提示了,找到如下字段:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
oracle ALL=(ALL) ALL
aaa ALL=(ALL) ALL
添加aaa用户,添加后如aaa ALL=(ALL) ALL
修改完后输入:wq保存,保存后记得把权限修改回去,否则会有错误提示
#chmod 440 /etc/sudoers 权限一定是440,否则就会有错误提示。
OK,在aaa用户下就可以正常使用sudo命令咯。
sudo 命令详解的更多相关文章
- (6)sudo命令详解(每周一个linux命令系列)
首先说句抱歉,最近事情比较复杂,停更了一阵子.我又回来啦 多用户管理 我们常用的windows个人系统虽然可以设置多用户,但是实际上是不可以多用户同时登陆的(这个我实验过,我以前用windows服务器 ...
- su和sudo命令详解
我们知道,在Linux下对很多文件进行修改都需要有root(管理员)权限,比如对/ect/profile等文件的修改.很多情况下,我们在进行开发的时候都是使用普通用户进行登录的,尤其在进行一些环境变量 ...
- linux sudo命令详解
--sudo命令重启网卡 sudo service network restart http://bestchenwu.iteye.com/blog/1450292
- sudo命令详解
语法 sudo(选项)(参数) 选项 选项 说明 -b 在后台执行指令: -h 显示帮助: -H 将HOME环境变量设为新身份的HOME环境变量: -k 结束密码的有效期限,也就是下次再执行sudo时 ...
- linux yum命令详解
yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...
- linux yum命令详解-转
yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...
- 【转】linux yum命令详解
yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...
- yum命令详解
yum(全 称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载 ...
- kill 命令详解 系统信号
kill 命令详解 系统信号 参考: 了解Linux的进程与线程 http://www.cnblogs.com/MYSQLZOUQI/p/4234005.html Linux就这个范儿 P532 ...
随机推荐
- javascript traverse object attributes 遍历对象属性
* for in for (var prop in o) { if (o.hasOwnProperty(prop)) { console.log(o[prop]); } } * Object keys ...
- vue-cli3 取消eslint 校验代码
项目生成后会有个.eslintrc.js文件 module.exports = { root: true, env: { node: true }, 'extends': [ 'plugin:vue/ ...
- P2179-[NOI2012]骑行川藏【导数,二分】
正题 题目链接:https://www.luogu.com.cn/problem/P2179 题目大意 给出\(E\)和\(n\)个\(s_i,k_i,u_i\)求一个序列\(v_i\)满足 \[\s ...
- Python : TypeError: 'int' object is not iterable
用循环依次对list中的每个名字打印出 Hello, xxx! -------------------------------------------------------- L = ['Bart' ...
- 基于C++的ButeBuf封装
目录 1.说明 2.代码 1.说明 netty 的 ByteBuf 中的 readerIndex 和 writerIndex 的设置十分巧妙,它内部对读取和写入位置进行控制,避免自己处理index的时 ...
- [洛谷日报#204] StackEdit——Markdown 编辑器的功能介绍
本文同时发表于洛谷日报,您也可以通过洛谷博客进行查看. 1.介绍与开始使用 1.1 这是什么? StackEdit是基于PageDown.Stack Overflow和其他堆栈交换站点使用的Markd ...
- xmake v2.5.8 发布,新增 Pascal/Swig 程序和 Lua53 运行时支持
xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能 ...
- 解决Vite-React项目中js使用jsx语法报错的问题
背景 在做存量项目接入Vite测试时发现,存量(老)项目中很多是直接在js中书写jsx语法,使用Vite启动时就会抛出一堆问题Failed to parse source. 不嫌麻烦可以跑个脚本批量修 ...
- Ysoserial Commons Collections2分析
Ysoserial Commons Collections2分析 About Commons Collections2 CC2与CC1不同在于CC2用的是Commons Collections4.0; ...
- CF850E Random Elections 题解
题目传送门 题目大意 没法描述,过于繁杂. 思路 果然自己是个菜鸡,只能靠读题解读题,难受极了,其实不是很难自己应该做得出来的....哎.... 不难发现可以统计 \(A\) 获胜的情况乘上 \(3\ ...