【问题标题】:How "sudo" command works?“sudo”命令如何工作?
【发布时间】:2013-09-04 10:40:09
【问题描述】:
我的理解是 sudo 是以 root 权限执行给定的 command,但我体验到在终端中输入带有 sudo 缓存的命令授权。它实际上是如何工作的?
例如
sudo fdisk -l
[sudo] password for xxxxx:
(一旦我通过输入密码进行授权,连续的 sudo 命令不会提示输入密码)
sudo fdisk -l
(不提示输入密码)
sudo mount -t vfat /dev/sda1 /media/test
sudo 是否真的是 su(替代/切换用户)的包装器?
【问题讨论】:
标签:
linux
ubuntu
terminal
ubuntu-12.04
sudo
【解决方案1】:
man sudo 会告诉你:
Security policies may support credential caching to allow the user to
run sudo again for a period of time without requiring authentication.
The sudoers policy caches credentials for 15 minutes, unless overridden
in sudoers(5). By running sudo with the -v option, a user can update
the cached credentials without running a command.
它还说:
-k [command]
When used alone, the -k (kill) option to sudo invalidates
the user's cached credentials. The next time sudo is run a
password will be required. This option does not require a
password and was added to allow a user to revoke sudo
permissions from a .logout file. Not all security policies
support credential caching.
When used in conjunction with a command or an option that
may require a password, the -k option will cause sudo to
ignore the user's cached credentials. As a result, sudo
will prompt for a password (if one is required by the
security policy) and will not update the user's cached
credentials.
【解决方案2】:
这里有适合您的详细信息:
是的 sudo 和 su 命令有点不同:
1.) 当我们启动 su 命令时,它将充当纯管理员(我们可以在该会话时间内永久保持相同)
2.) 鉴于 sudo 命令充当拥有或分配管理员权限(我们只能说该会话是临时的)
另一个例子:
在windows系统中,希望你勾选了“以管理员身份运行”之类的右键属性,这和sudo一样。
如果我们登录或将用户切换到管理员,它纯粹充当所有程序的管理员。
希望你能理解我的例子,这对我来说是最好的
【解决方案3】:
您可以在 /etc/sudoers 中编辑 sudo 配置。
授权有默认超时时间。
您甚至可以使用 sudo 分配一些用户,而无需密码。
或者某些用户一旦授权,在您注销系统之前不需要密码。