Linux基础:用户权限
普通用户如何执行root权限命令?
1. sudo:super user do,以超级用户的方式执行命令。指令格式为:
sudo 指令当前用户的密码
sudo是一种权限管理机制,其权限管理记录在/etc/sudoers文件中,约定普通用户可以以管理员的身份执行命令。
基本运行机制为:普通用户执行sudo命令时,查找/etc/sudoers文件以确定该用户是否具有执行权限;若有,则提示用户输入自己的密码,密码正确则执行sudo对应的命令。
root@linux:/etc# cat sudoers## This file MUST be edited with the 'visudo' command as root.## Please consider adding local content in /etc/sudoers.d/ instead of# directly modifying this file.## See the man page for details on how to write a sudoers file.#Defaultsenv_resetDefaultsmail_badpassDefaultssecure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"# Host alias specification# User alias specification# Cmnd alias specification# User privilege specificationrootALL=(ALL:ALL) ALLlinuxALL=(ALL:ALL) ALL# Members of the admin group may gain root privileges%admin ALL=(ALL) ALL# Allow members of group sudo to execute any command%sudoALL=(ALL:ALL) ALL# See sudoers(5) for more information on "#include" directives:#includedir /etc/sudoers.d
2. su:switch user,切换用户
如切换到root用户下,可执行命令:
su root输入root密码
执行完操作后,也可以退出root用户
root@linux:/etc# exitexit
事实上,还有另外一种格式:
su -l root(-l)
su的两种格式区别在于:-l为login的首字母,登录后使用全新的环境变量。
