概述
1、sudo
sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等。这样不仅减少了root用户的登录 和管理时间,同样也提高了安全性。sudo不是对shell的一个代替,它是面向每个命令的。当用户调用sudo并且输入它的密码时,用户获得了一张存活期为5分钟的票(这个值可以在编译的时候改变),五分钟后登陆需要重新输入密码。
2、/etc/sudoers
首先要明白root的密码一般用户是不应改知道的,但一般用户有时可能要用到root的一些权限。
这里就有了一个 /etc/sudoers文件,用来保存一些用户,使这些用户可以通过sudo命令来暂时获取root的权限。这些用户使用sudo时输入的密码是当前用户密码,而不是root密码。还可一在sudoers文件里限制一般用户的权限,这样就有了安全保证。
该文件的默认权限是440,没有写权限,可以使用visudo命令修改该文件,也可以在root用户下修改权限后,修改文件,再修改回去。
[root@VM_0_11_centos ~]# cat /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.
## Allow root to run any commands anywhere
root
ALL=(ALL)
ALL
用户
主机名
以什么身份
执行什么命令
3、提升权限
1)添加普通用户
[root@VM_0_11_centos ~]# useradd test
[root@VM_0_11_centos ~]# su test
[test@VM_0_11_centos root]$ sudo -l
2)普通用户没有执行ls命令权限
[test@VM_0_11_centos root]$ ll
ls: cannot open directory .: Permission denied
[test@VM_0_11_centos root]$ ls
ls: cannot open directory .: Permission denied
3)编辑/etc/sudoers
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users
ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
# %users
localhost=/sbin/shutdown -h now
## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
test ALL=(ALL) NOPASSWD: /bin/ls
4)切换到test用户执行ls命令
[test@VM_0_11_centos root]$ sudo ls
core_pattern~
kernel-debug
nohup.out
panic_on_oom~
panic_on_ooz~
rpmbuild
[test@VM_0_11_centos root]$
最后
以上就是眯眯眼睫毛为你收集整理的Linux 权限提升--sudo的全部内容,希望文章能够帮你解决Linux 权限提升--sudo所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复