sudo 命令无法使用
程序员文章站
2022-05-10 09:42:50
...
1. 不能使用sudo命令解决方法:
想查看这个用户可以使用哪些sudo命令,输入正确密码却不能查看,原因就是在/etc/sudoers中未添加该用户。
[[email protected] ~]$ sudo -l
[sudo] password for xm:
Sorry, user xm may not run sudo on oracle.
2.解决方法(添加用户至sudoers文件):
(1) 切换root用户
[[email protected] ~]$ su - root
Password:
[[email protected] ~]#
(2) 添加用户至 sudoers 文件(vim /etc/sudoers 或者 visudo)
[[email protected] ~]# visudo
## 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.
## Host Aliases
## Groups of machines. You may prefer to use hostnames (perhaps using
## wildcards for entire domains) or IP addresses instead.
# Host_Alias FILESERVERS = fs1, fs2
# Host_Alias MAILSERVERS = smtp, smtp2
## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS
# User_Alias ADMINS = jsmith, mikem
在93行的位置添加该用户,正常退出即可
90 ## Allow root to run any commands anywhere
91 root ALL=(ALL) ALL
92 xh ALL=(ALL) ALL
93 xm ALL=(ALL) ALL
94 ## Allows members of the 'sys' group to run networking, software,
95 ## service management apps and more.
96 # %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
(3) 正常使用sudo命令
[[email protected] ~]# su - xm
[[email protected] ~]$ sudo -l
[sudo] password for xm:
Matching Defaults entries for xm on this host:
!visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME
HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG
LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT
LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE",
env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY",
secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin
User xm may run the following commands on this host:
(ALL) ALL
由结果看出:可以执行的sudo命令为所有ALL
上一篇: pycharm中运行文件调包