Linux用户配置sudo权限(visudo)的方法
sudo的工作过程如下:
1,当用户执行sudo时,系统会主动寻找/etc/sudoers文件,判断该用户是否有执行sudo的权限
2,确认用户具有可执行sudo的权限后,让用户输入用户自己的密码确认
3,若密码输入成功,则开始执行sudo后续的命令
4,root执行sudo时不需要输入密码(eudoers文件中有配置rootALL=(ALL)ALL这样一条规则)
5,若欲切换的身份与执行者的身份相同,也不需要输入密码
visudo使用vi打开/etc/sudoers文件,但是在保存退出时,visudo会检查内部语法,避免用户输入错误信息
visudo需要root权限
[hadoop@localhost~]$visudo visudo:/etc/sudoers:权限不够 visudo:/etc/sudoers:权限不够使用visudo命令打开sudo配置文件 ##Sudoersallowsparticularuserstorunvariouscommandsas ##therootuser,withoutneedingtherootpassword. ##该文件允许特定用户像root用户一样使用各种各样的命令,而不需要root用户的密码 ## ##Examplesareprovidedatthebottomofthefileforcollections ##ofrelatedcommands,whichcanthenbedelegatedouttoparticular ##usersorgroups. ##在文件的底部提供了很多相关命令的示例以供选择,这些示例都可以被特定用户或 ##用户组所使用 ## ##Thisfilemustbeeditedwiththe'visudo'command. ##该文件必须使用"visudo"命令编辑 ##HostAliases ##Groupsofmachines.Youmayprefertousehostnames(perhapsusing ##wildcardsforentiredomains)orIPaddressesinstead. ##对于一组服务器,你可能会更喜欢使用主机名(可能是全域名的通配符) ##、或IP地址,这时可以配置主机别名 #Host_AliasFILESERVERS=fs1,fs2 #Host_AliasMAILSERVERS=smtp,smtp2 ##UserAliases ##Thesearen'toftennecessary,asyoucanuseregulargroups ##(ie,fromfiles,LDAP,NIS,etc)inthisfile-justuse%groupname ##ratherthanUSERALIAS ##这并不很常用,因为你可以通过使用组来代替一组用户的别名 #User_AliasADMINS=jsmith,mikem ##CommandAliases ##Thesearegroupsofrelatedcommands... ##指定一系列相互关联的命令(当然可以是一个)的别名,通过赋予该别名sudo权限, ##可以通过sudo调用所有别名包含的命令,下面是一些示例 ##Networking网络操作相关命令别名 #Cmnd_AliasNETWORKING=/sbin/route,/sbin/ifconfig,/bin/ping,/sbin/dhclient ,/usr/bin/net,/sbin/iptables,/usr/bin/rfcomm,/usr/bin/wvdial,/sbin/iwconfig ,/sbin/mii-tool ##Installationandmanagementofsoftware软件安装管理相关命令别名 #Cmnd_AliasSOFTWARE=/bin/rpm,/usr/bin/up2date,/usr/bin/yum ##Services服务相关命令别名 #Cmnd_AliasSERVICES=/sbin/service,/sbin/chkconfig ##Updatingthelocatedatabase本地数据库升级命令别名 #Cmnd_AliasLOCATE=/usr/bin/updatedb ##Storage磁盘操作相关命令别名 #Cmnd_AliasSTORAGE=/sbin/fdisk,/sbin/sfdisk,/sbin/parted,/sbin/partprobe ,/bin/mount,/bin/umount ##Delegatingpermissions代理权限相关命令别名 #Cmnd_AliasDELEGATING=/usr/sbin/visudo,/bin/chown,/bin/chmod,/bin/chgrp ##Processes进程相关命令别名 #Cmnd_AliasPROCESSES=/bin/nice,/bin/kill,/usr/bin/kill,/usr/bin/killall ##Drivers驱动命令别名 #Cmnd_AliasDRIVERS=/sbin/modprobe #Defaultsspecification # #Disable"sshhostnamesudo<cmd>",becauseitwillshowthepasswordinclear. #Youhavetorun"ssh-thostnamesudo<cmd>". #一些环境变量的相关配置,具体情况可见mansoduers Defaultsrequiretty Defaultsenv_reset Defaultsenv_keep="COLORSDISPLAYHOSTNAMEHISTSIZEINPUTRCKDEDIRLS_COLORS" Defaultsenv_keep+="MAILPS1PS2QTDIRUSERNAMELANGLC_ADDRESSLC_CTYPE" Defaultsenv_keep+="LC_COLLATELC_IDENTIFICATIONLC_MEASUREMENTLC_MESSAGES" Defaultsenv_keep+="LC_MONETARYLC_NAMELC_NUMERICLC_PAPERLC_TELEPHONE" Defaultsenv_keep+="LC_TIMELC_ALLLANGUAGELINGUAS_XKB_CHARSETXAUTHORITY" Defaultssecure_path=/sbin:/bin:/usr/sbin:/usr/bin ##Nextcomesthemainpart:whichuserscanrunwhatsoftwareon ##whichmachines(thesudoersfilecanbesharedbetweenmultiple ##systems). ##下面是规则配置:什么用户在哪台服务器上可以执行哪些命令(sudoers文件可以在多个系统上共享) ##Syntax(语法): ## ##userMACHINE=COMMANDS用户登录的主机=(可以变换的身份)可以执行的命令 ## ##TheCOMMANDSsectionmayhaveotheroptionsaddedtoit. ##命令部分可以附带一些其它的选项 ## ##Allowroottorunanycommandsanywhere ##允许root用户执行任意路径下的任意命令 rootALL=(ALL)ALL ##Allowsmembersofthe'sys'grouptorunnetworking,software, ##servicemanagementappsandmore. ##允许sys中户组中的用户使用NETWORKING等所有别名中配置的命令 #%sysALL=NETWORKING,SOFTWARE,SERVICES,STORAGE,DELEGATING,PROCESSES,LOCATE ,DRIVERS ##Allowspeopleingroupwheeltorunallcommands ##允许wheel用户组中的用户执行所有命令 %wheelALL=(ALL)ALL ##Samethingwithoutapassword ##允许wheel用户组中的用户在不输入该用户的密码的情况下使用所有命令 #%wheelALL=(ALL)NOPASSWD:ALL ##Allowsmembersoftheusersgrouptomountandunmountthe ##cdromasroot ##允许users用户组中的用户像root用户一样使用mount、unmount、chrom命令 #%usersALL=/sbin/mount/mnt/cdrom,/sbin/umount/mnt/cdrom ##Allowsmembersoftheusersgrouptoshutdownthissystem ##允许users用户组中的用户关闭localhost这台服务器 #%userslocalhost=/sbin/shutdown-hnow ##Readdrop-infilesfrom/etc/sudoers.d(the#heredoesnotmeanacomment) ##读取放置在/etc/sudoers.d/文件夹中的文件(此处的#不意味着这是一个声明) #includedir/etc/sudoers.d
特别要注意的是别名一定要使用大写
以上这篇Linux用户配置sudo权限(visudo)的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。