iis服务器助手广告广告
返回顶部
首页 > 资讯 > 操作系统 >Linux sudo命令怎么用
  • 537
分享到

Linux sudo命令怎么用

2023-06-28 17:06:55 537人浏览 八月长安
摘要

linux sudo命令怎么用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Linux sudo命令以系统管理者的身份执行指令,也就是说,经由 sudo 所执行

linux sudo命令怎么用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

Linux sudo命令以系统管理者的身份执行指令,也就是说,经由 sudo 所执行的指令就好像是 root 亲自执行。
使用权限:在 /etc/sudoers 中有出现的使用者。

语法
sudo -V
sudo -h
sudo -l
sudo -v
sudo -k
sudo -s
sudo -H
sudo [ -b ] [ -p prompt ] [ -u username/#uid] -s
sudo command
参数说明:

-V 显示版本编号
-h 会显示版本编号及指令的使用方式说明
-l 显示出自己(执行 sudo 的使用者)的权限
-v 因为 sudo 在第一次执行时或是在 N 分钟内没有执行(N 预设为五)会问密码,这个参数是重新做一次确认,如果超过 N 分钟,也会问密码
-k 将会强迫使用者在下一次执行 sudo 时问密码(不论有没有超过 N 分钟)
-b 将要执行的指令放在背景执行
-p prompt 可以更改问密码的提示语,其中 %u 会代换为使用者的帐号名称, %h 会显示主机名称
-u username/#uid 不加此参数,代表要以 root 的身份执行指令,而加了此参数,可以以 username 的身份执行指令(#uid 为该 username 的使用者号码)
-s 执行环境变数中的 shell 所指定的 shell ,或是 /etc/passwd 里所指定的 shell
-H 将环境变数中的 HOME (家目录)指定为要变更身份的使用者家目录(如不加 -u 参数就是系统管理者 root )
command 要以系统管理者身份(或以 -u 更改为其他人)执行的指令
实例
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系统

Linux是一种免费使用和自由传播的类UNIX操作系统,是一个基于POSIX的多用户、多任务、支持多线程和多CPU的操作系统,使用Linux能运行主要的Unix工具软件、应用程序和网络协议。

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注编程网操作系统频道,感谢您对编程网的支持。

--结束END--

本文标题: Linux sudo命令怎么用

本文链接: https://www.lsjlt.com/news/320890.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Linux sudo命令怎么用
    Linux sudo命令怎么用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Linux sudo命令以系统管理者的身份执行指令,也就是说,经由 sudo 所执行...
    99+
    2023-06-28
  • Linux的su、sudo、sudo su、sudo -i命令怎么用
    这篇文章主要介绍了Linux的su、sudo、sudo su、sudo -i命令怎么用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Linux的su、sudo、sudo su、sudo -i命令怎么用文章都会有...
    99+
    2023-06-27
  • Linux中sudo命令怎么用
    这篇文章给大家分享的是有关Linux中sudo命令怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。Linux常用命令sudo命令 用来以其他身份来执行命令,预设的身份为root。在/etc/sudoers中设...
    99+
    2023-06-28
  • Linux sudo命令怎么使用
    这篇文章主要介绍“Linux sudo命令怎么使用”,在日常操作中,相信很多人在Linux sudo命令怎么使用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Linux sudo命令怎么使用”的疑惑有所帮助!...
    99+
    2023-06-28
  • linux下的sudo命令怎么使用
    本文小编为大家详细介绍“linux下的sudo命令怎么使用”,内容详细,步骤清晰,细节处理妥当,希望这篇“linux下的sudo命令怎么使用”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。sudo是linux下常用...
    99+
    2023-06-27
  • Linux系统中sudo命令怎么用
    这篇文章主要介绍了Linux系统中sudo命令怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。sudo:它有什么用途?那么,sudo实际能做些什么呢?如果你在任何Linu...
    99+
    2023-06-16
  • linux系统sudo命令如何使用
    今天小编给大家分享一下linux系统sudo命令如何使用的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来...
    99+
    2023-05-25
    linux sudo
  • linux系统中如何使用sudo命令
    这篇文章主要为大家展示了“linux系统中如何使用sudo命令”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“linux系统中如何使用sudo命令”这篇文章吧。Linux 下使用Sudo 命令,可...
    99+
    2023-06-28
  • 怎么免sudo使用docker命令详解
    这篇文章主要介绍怎么免sudo使用docker命令详解,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!背景docker是paas供应商dotcloud开源的一个基于lxc 的高级容器引擎,源代码托管在 github 上...
    99+
    2023-06-07
  • Linux下如何正确使用sudo命令
    这篇“Linux下如何正确使用sudo命令”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Linux下如何正确使用sudo命令...
    99+
    2023-06-27
  • Linux系统中su和sudo命令的用法
    这篇文章主要介绍“Linux系统中su和sudo命令的用法”,在日常操作中,相信很多人在Linux系统中su和sudo命令的用法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Linux系统中su和sudo命令...
    99+
    2023-06-12
  • linux中Sudo命令使用技巧有哪些
    这篇文章主要介绍了linux中Sudo命令使用技巧有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。sudo 表示 “superuser do”,它允许已验证的用户以其他用...
    99+
    2023-06-15
  • Linux命令学习之用户切换su,sudo命令详解
    目录用户切换相关命令1. su命令2. sudo命令赋予用户sudo操作的权限用公式讲解/etc/sudoers的内容公式还要扩充通配符和取消命令开始编辑其他小知识用户切换相关命令 为什么要进行用户切换? 在操作过程中需...
    99+
    2023-02-08
    Linux用户切换su sudo Linuxsu sudo切换用户
  • 如何在Linux系统中使用sudo命令
    如何在Linux系统中使用sudo命令?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。“Sudo” 是Unix/Linux平台上的一个非常有用的工具,它允许系统管理员分配给普...
    99+
    2023-06-12
  • 如何理解Linux中的sudo命令
    这篇文章主要介绍“如何理解Linux中的sudo命令”,在日常操作中,相信很多人在如何理解Linux中的sudo命令问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何理解Linux中的sudo命令”的疑惑有所...
    99+
    2023-06-13
  • linux的sudo命令有哪些功能
    这篇文章主要介绍“linux的sudo命令有哪些功能”,在日常操作中,相信很多人在linux的sudo命令有哪些功能问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”linux的sudo命令有哪些功能”的疑惑有所...
    99+
    2023-06-06
  • linux中Sudo授权命令的使用方法
    linux中Sudo授权命令的使用方法?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。第一种方案:su root -c "你要执行的命令"其实是切换用户,由当...
    99+
    2023-06-12
  • Linux的su和sudo命令有什么区别
    今天小编给大家分享一下Linux的su和sudo命令有什么区别的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。Linux su...
    99+
    2023-06-28
  • linux中Sudo命令的使用技巧有哪些
    这篇文章将为大家详细讲解有关linux中Sudo命令的使用技巧有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。简单的说,sudo 是一种权限管理机制,管理员可以授权于一些普通用户去执行一些 root ...
    99+
    2023-06-28
  • linux中su与sudo命令的区别是什么
    这篇文章将为大家详细讲解有关linux中su与sudo命令的区别是什么,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。一. 使用 su 命令临时切换用户身份su 的适用条件和威力  su命令就...
    99+
    2023-06-13
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作