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 //就可以查看防火墙的状态

猜你喜欢

转载自blog.csdn.net/caoPengFlying/article/details/82084211