Linux Command - sudo学习

在linux操作系统是一个多用户系统,root用户拥有执行所有命令的权利,但是普通用户没有这个权利
这是因为在sudo这个文件中没有配置其他用户的命令权利。
我们在使用中,经常要用到普通用户去执行命令,比如开启防火墙,关闭防火墙等,在不切换到root用户前提下,必须要修改sudo这个文件才能拥有命令。
sudo文件详解:
1输入命令visudo 并输入大写的G(光标跳转到最后)会提示下面的内容

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS

## Allows people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL

## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL

## 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

里面的代码很多都是被注释掉的,找到root ALL=(ALL) ALL这一行,前面没有#号
就因为这一行所以root用户拥有所有的命令权限。
root表示用户名
ALL表示在任意主机登录
=(ALL)表示以什么样的身份登录
最后的ALL 表示拥有全部的命令权限
现在要给普通用户添加所有权限的命令 :在这一行下面添加

username    ALL=(root)  ALL

这样的话username用户也可执行所有的root命令,但是在执行前要输入密码 ,如果想不要输入密码改为

username ALL=(root) NOPASSWD:ALL

然后登录普通用户执行

sudo service iptables status //就可以查看防火墙的状态
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值