Linux 权限提升--sudo

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]$

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值