学习啦 > 学习电脑 > 操作系统 > Linux教程 >

linux的sudo命令实例分析介绍

时间: 加城1195 分享

  Linux sudo命令以系统管理者的身份执行指令,也就是说,经由 sudo 所执行的指令就好像是 root 亲自执行。具体怎么使用呢。下面由学习啦小编为大家整理了linux的sudo命令的相关知识,希望大家喜欢!

  linux的sudo命令实例

  sudo命令使用

  $ sudo ls

  [sudo] password for hnlinux:

  hnlinux is not in the sudoers file. This incident will be reported.

学习啦在线学习网   指定用户执行命令

  # sudo -u userb ls -l

  显示sudo设置

  $ sudo -L //显示sudo设置

  Available options in a sudoers ``Defaults'' line:

  syslog: Syslog facility if syslog is being used for logging

  syslog_goodpri: Syslog priority to use when user authenticates successfully

学习啦在线学习网   syslog_badpri: Syslog priority to use when user authenticates unsuccessfully

  long_otp_prompt: Put OTP prompt on its own line

学习啦在线学习网   ignore_dot: Ignore '.' in $PATH

  mail_always: Always send mail when sudo is run

  mail_badpass: Send mail if user authentication fails

  mail_no_user: Send mail if the user is not in sudoers

  mail_no_host: Send mail if the user is not in sudoers for this host

  mail_no_perms: Send mail if the user is not allowed to run a command

学习啦在线学习网   tty_tickets: Use a separate timestamp for each user/tty combo

学习啦在线学习网   lecture: Lecture user the first time they run sudo

  lecture_file: File containing the sudo lecture

学习啦在线学习网   authenticate: Require users to authenticate by default

  root_sudo: Root may run sudo

  log_host: Log the hostname in the (non-syslog) log file

学习啦在线学习网   log_year: Log the year in the (non-syslog) log file

学习啦在线学习网   shell_noargs: If sudo is invoked with no arguments, start a shell

学习啦在线学习网   set_home: Set $HOME to the target user when starting a shell with -s

学习啦在线学习网   always_set_home: Always set $HOME to the target user's home directory

  path_info: Allow some information gathering to give useful error messages

  fqdn: Require fully-qualified hostnames in the sudoers file

学习啦在线学习网   insults: Insult the user when they enter an incorrect password

学习啦在线学习网   requiretty: Only allow the user to run sudo if they have a tty

学习啦在线学习网   env_editor: Visudo will honor the EDITOR environment variable

学习啦在线学习网   rootpw: Prompt for root's password, not the users's

  runaspw: Prompt for the runas_default user's password, not the users's

学习啦在线学习网   targetpw: Prompt for the target user's password, not the users's

  use_loginclass: Apply defaults in the target user's login class if there is one

学习啦在线学习网   set_logname: Set the LOGNAME and USER environment variables

学习啦在线学习网   stay_setuid: Only set the effective uid to the target user, not the real uid

  preserve_groups: Don't initialize the group vector to that of the target user

  loglinelen: Length at which to wrap log file lines (0 for no wrap)

  timestamp_timeout: Authentication timestamp timeout

  passwd_timeout: Password prompt timeout

  passwd_tries: Number of tries to enter a password

  umask: Umask to use or 0777 to use user's

学习啦在线学习网   logfile: Path to log file

学习啦在线学习网   mailerpath: Path to mail program

  mailerflags: Flags for mail program

  mailto: Address to send mail to

学习啦在线学习网   mailfrom: Address to send mail from

  mailsub: Subject line for mail messages

学习啦在线学习网   badpass_message: Incorrect password message

学习啦在线学习网   timestampdir: Path to authentication timestamp dir

  timestampowner: Owner of the authentication timestamp dir

学习啦在线学习网   exempt_group: Users in this group are exempt from password and PATH requirements

  passprompt: Default password prompt

  passprompt_override: If set, passprompt will override system prompt in all cases.

  runas_default: Default user to run commands as

  secure_path: Value to override user's $PATH with

  editor: Path to the editor for use by visudo

学习啦在线学习网   listpw: When to require a password for 'list' pseudocommand

  verifypw: When to require a password for 'verify' pseudocommand

  noexec: Preload the dummy exec functions contained in 'noexec_file'

  noexec_file: File containing dummy exec functions

学习啦在线学习网   ignore_local_sudoers: If LDAP directory is up, do we ignore local sudoers file

  closefrom: File descriptors >= %d will be closed before executing a command

学习啦在线学习网   closefrom_override: If set, users may override the value of `closefrom' with the -C option

  setenv: Allow users to set arbitrary environment variables

学习啦在线学习网   env_reset: Reset the environment to a default set of variables

  env_check: Environment variables to check for sanity

学习啦在线学习网   env_delete: Environment variables to remove

学习啦在线学习网   env_keep: Environment variables to preserve

学习啦在线学习网   role: SELinux role to use in the new security context

  type: SELinux type to use in the new security context

  askpass: Path to the askpass helper program

学习啦在线学习网   env_file: Path to the sudo-specific environment file

  sudoers_locale: Locale to use while parsing sudoers

  visiblepw: Allow sudo to prompt for a password even if it would be visisble

学习啦在线学习网   pwfeedback: Provide visual feedback at the password prompt when there is user input

  fast_glob: Use faster globbing that is less accurate but does not access the filesystem

学习啦在线学习网   umask_override: The umask specified in sudoers will override the user's, even if it is more permissive

  以root权限执行上一条命令

学习啦在线学习网   $ sudo !!

学习啦在线学习网   以特定用户身份进行编辑文本

  $ sudo -u uggc vi ~www/index.html

  //以 uggc 用户身份编辑 home 目录下www目录中的 index.html 文件

  列出目前的权限

  sudo -l

  列出 sudo 的版本资讯

  sudo -V

  相关阅读:Linux常用基本命令

  文件名--test

  mkdir test 创建一个文件夹

学习啦在线学习网   mkdir test/test1/test2 -p 在创建test1时候,继续创建test2目录,一起创建

  mv test test1 修改文件名称

学习啦在线学习网   mv test /位置 复制文件到指定位置

  cat test 查看文件内容

学习啦在线学习网   unzip 解压包 解压当前文件

学习啦在线学习网   unzip 解压包 -d /位置 解压压缩包到指定位置

  rm test 删除一个文件

学习啦在线学习网   rm -rf test 删除一个带文件或者文件夹的 文件目录

  cp test test1 复制一个文件

学习啦在线学习网   cp -r test test1 复制一个文件夹(包含文件夹下的文件)

  vi 文件名 修改文件内容

  按i键,下方出现insert,开始编辑内容

  编辑完内容,按esc,退出编辑模式

学习啦在线学习网   :wq 保存退出

  :q! 不保存文件退出

学习啦在线学习网   启动报错,给权限

  chmod 777 ./startup.sh

  chmod -R 777 catalina.sh

  重启nginx: 进入到nginx的sbin目录,重启: ./nginx -s reload(也意指在不关机的情况下,刷新配置文件)

学习啦在线学习网   启动nginx: 进入到nginx的sbin目录,命令./nginx 开启服务

学习啦在线学习网   关闭nginx: 进入到nginx的sbin目录,命令./nginx -s stop(./nginx -s quit) 关闭服务

3996458