sudo
Posted Books&Coffee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sudo相关的知识,希望对你有一定的参考价值。
在非root权限下,无法执行 vim /etc/profile 并保存,提示如下错误:
"profile" E212: Can‘t open file for writing
Press ENTER or type command to continue
但是可以执行 sudo vim /etc/profile 。
sudo的作用大体可以理解为:
为非root用户赋予一些root用户才有的操作权限。
只有在/etc/profile有记录的用户才能执行sudo操作
将当前用户设置成 管理员(在当前操作系统中设置即可)即可使用sudo操作。
eg:
cat /etc/sudoers
权限不足,如下所示:
cat: /etc/sudoers: Permission denied
sudo cat /etc/sudoers
输入如下结果:
#
# Sample /etc/sudoers file.
#
# This file MUST be edited with the ‘visudo‘ command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
##
# Override built-in defaults
##
Defaults env_reset
Defaults env_keep += "BLOCKSIZE"
Defaults env_keep += "COLORFGBG COLORTERM"
Defaults env_keep += "__CF_USER_TEXT_ENCODING"
Defaults env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"
Defaults env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"
Defaults env_keep += "LINES COLUMNS"
Defaults env_keep += "LSCOLORS"
Defaults env_keep += "SSH_AUTH_SOCK"
Defaults env_keep += "TZ"
Defaults env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
Defaults env_keep += "EDITOR VISUAL"
Defaults env_keep += "HOME MAIL"
Defaults lecture_file = "/etc/sudo_lecture"
##
# User alias specification
##
# User_Alias FULLTIMERS = millert, mikef, dowdy
##
# Runas alias specification
##
# Runas_Alias OP = root, operator
##
# Host alias specification
##
# Host_Alias CUNETS = 128.138.0.0/255.255.0.0
# Host_Alias CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
# Host_Alias SERVERS = master, mail, www, ns
# Host_Alias CDROM = orion, perseus, hercules
##
# Cmnd alias specification
##
# Cmnd_Alias PAGERS = /usr/bin/more, /usr/bin/pg, /usr/bin/less
##
# User specification
##
# root and users in group wheel can run anything on any machine as any user
root ALL = (ALL) ALL
%admin ALL = (ALL) ALL
## Read drop-in files from /private/etc/sudoers.d
## (the ‘#‘ here does not indicate a comment)
#includedir /private/etc/sudoers.d
以上是关于sudo的主要内容,如果未能解决你的问题,请参考以下文章